Is it possible to use a dynamic value in asp-route-{value}?

Viewed 377

I have Razor Page with the following piece of code to create a link that adds a dynamic value to the route when clicked. This works perfectly.

<a class="page-link" asp-route-systemRightsPage="@(i.Index)">@i.Index</a>

Now, I have different values for the route, in this case I'm using systemRightsPage, but I also have 3 more types that I can navigate to (personsPage, personRightsPage, errorsPage), and so on.

Is it possible to use somehow a dynamic value on the asp-route-{value} part? I tried using this:

<a class="page-link" asp-route-@(RouteValue)="@(i.Index)">@i.Index</a>

This code renders correctly in HTML to:

<a class="page-link" asp-route-personpage="2">2</a>

But the link doesn't work anymore, as nothing happens if I click it.

Has anyone done anything similar?

1 Answers
Related