Blazor Route define Param Segment without defining Parameter Property

192 Views Asked by At

We need razor parameter But Just in url not in Code @page "/FirstEntity/{FirstEntityId}/SecondEntity/{SecondEntityId}/ThirdEntity" We need All Path For NavigationManager But For ApiRequest We Just Need SecondEntityId parameter.

For These reasons we Just Define one Parameter in Code: [Parameter, EditorRequired] public string SecondEntityId { get; set; } But Blazor Show Error for not Defining FirstEntityId property As Parameter.

this Sample is Just for Two Level Entity and Have 2 ParentId, when Levels Go up Things Get worth and wen can not Define More Than one Parameter in BaseComponets Which We Don't know How many they will be. What Can We DO?

1

There are 1 best solutions below

0
On

We Don't know How many they will be. What Can We DO?

As mentioned in a comment, the best thing is probably to look at your design here.

But if you really want to handle multiple parameters for an unknown depth, you can use a catch-all like {*allTheRest}. And then parse that string.

"/FirstEntity/{*AllTheRest}"

...

[Parameter] public string AllTheRest { get; set; }  // "SecondEntity/22/ThirdEntity"

You can split and parse that.