'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 1:[1]
Building on Surinder's answer, here is an expanded example with the child code that worked to get the object.
PARENT
<CascadingValue Value="@anyObject" IsFixed="True" Name="AnyName">
<ComponentName />
</CascadingValue>
@code {
private ObjectType anyObject = new();
}
CHILD
@code {
[CascadingParameter(Name = "AnyName")]
private ObjectType anyObject { get; set; }
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
