Cascading Parameter

Posted 127 days ago by kmorgan26
0

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

    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.

    Posted 125 days ago by selliott
  • 0

    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 125 days ago by kmorgan26
Someone is typing...

Post a Reply

You must be logged in to add a new post.
Number of online users: 2
An error has occurred. This application may no longer respond until reloaded. Reload 🗙