.netcomponentsblazorcascading

Is there a shorthand for inserting .NET Blazor components with multiple cascading values?


I am working on a .NET Blazor project and need to pass multiple cascading values to a generic subform. The following code, which applies multiple [CascadingValue] attributes, works fine for passing a few values but becomes a little cumbersome when passing many more than that. Is there a shorthand for passing multiple values via a single [CascadingValue] attribute? If not, is there a more compact way to pass a larger number of values? (BTW - I do understand that there are alternatives to giving each attribute a name).

<CascadingValue Value="@Value1" Name = "Name1" > 
     <CascadingValue Value="@Value2" Name = "Name2" > 
            <CascadingValue Value="@Value3" Name = "Name3" > 
                <FooComponent />
             </CascadingValue>
     </CascadingValue>
</CascadingValue>

                                                               

Solution

  • You can create an object with all values you want to pass and use it like this

    <CascadingValue Value="@AnyObject" IsFixed="true">
    </CascadingValue>