Bob5421
Bob5421

Reputation: 9073

Use a route parameter in an attribute in a blazor server page

I am writing this page on a blazor-server application:

@page "/pageurl/{param:int}"
@attribute [AnAttribute(param)]

<div>@param</div>

@code
{
   [Parameter]
   public int param { get;set; }
}

As you can see, i am trying to pass the param as an argument of my attribute. It does not work. Maybe because when attribute is runned, blazor hasn't parsed parameters.

How can i use a page parameter as an attribute argument ?

Thanks

Upvotes: 0

Views: 508

Answers (1)

Ned Flanders
Ned Flanders

Reputation: 529

Parameters of an attribute must be known at compiletime. (Hard coded) It makes no difference whether RazorPage or other classes.

The only way to work around this, could be Reflection.

Upvotes: 1

Related Questions