I don't believe your issue is with the Cascading Parameter. It looks like the FormFieldComponent must be inside the StatusSelectComponent. If you add @StatusId outside the FormFieldComponent, you should see the value displayed. If you move the select element outside of the FormFieldComponent, it should load fine too. You might need to look into RenderFragment<T> and Context in order to work with data inside the FormFieldComponent.
Cascading Parameter
I have a question about using a cascading parameter when the parameter is a property inside of a class:
I have a class named TrackingFilter that holds several int? properties. In the Parent Component, I have an instance of the TrackingFilter
public TrackingFilter TrackingFilter { get; set; } = new();
One of the properties of that TrackingFilter is a StatusId of type int? I'm trying to use that property as a CascadingValue:
<CascadingValue Value="TrackingFilter.StatusId">
<StatusSelectComponent></StatusSelectComponent>
</CascadingValue>
The child component is a SelectList Component that has a CascadingParameter for the StatusId:
[CascadingParameter]
public int? StatusId { get; set; }
Here is the Markup that binds to the Property:
<FormFieldComponent LabelName="Status">
<ControlToRender>
<select @bind="@StatusId" class="custom-select">
<option value=0>-----</option>
@foreach(var item in _statusVms)
{
<option value="@item.Id">@item.Name</option>
}
</select>
</ControlToRender>
</FormFieldComponent>
I can pass in a complete TrackingFilter and it works fine, but then it's not usable with other components. Is it possible to pass a Parameter in this manner? It's not binding to the Parent as is.
Any help will be greatly appreciated. Also, I wish I could preview this post before I submit it! :)
1 Posted 2 years ago by selliott0 This wasn't the case since I could use the same markup but pass in a full TrackingFilter as a parameter and it worked fine. What I ended up doing is using a callback instead of the cascading param.
Posted 2 years ago by kmorgan26