2

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>

                                                               
geoCode
  • 89
  • 7

2 Answers2

4

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

<CascadingValue Value="@AnyObject" IsFixed="true">
</CascadingValue>
Surinder Singh
  • 1,165
  • 1
  • 3
  • 11
0

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; }
}
geoCode
  • 89
  • 7