TagHelper for passing route values as part of a link

mattdwen picture mattdwen · May 4, 2015 · Viewed 49.4k times · Source

When specifying asp-controller and asp-action on a link, what's the syntax for also passing an id attribute?

E.g. If I wanted to link to the edit URL for a given object, the required URL would be /user/edit/5 for example.

Is there a method to achieve this using TagHelpers, or do we still have to fall back to @Html.ActionLink()?

Answer

Kiran Challa picture Kiran Challa · May 5, 2015

You can use the attribute prefix asp-route- to prefix your route variable names.

Example: <a asp-action="Edit" asp-route-id="10" asp-route-foo="bar">Edit</a>