c# – How to use @Html.ActionLink to link to a multi-threaded route?


I would like to use @Html.ActionLink to create the following link:


Since my control is:

public async Task<ActionResult> Index(int? page)


I know how to use @Html.ActionLink passing parameters, but in this case the page parameter is part of the route.


You are using the Attribute Routing , then remembering only that you should call the method MapMvcAttributeRoutes () your RouteConfig with the following line:


Once that's done, just add the attribute to your controller , just like you're doing.

public async Task<ActionResult> Index(int? page)


Even this part I assume you already have, so now let's go to your ActionLink() .

@Html.ActionLink("TEXTO","Index","CONTROLLER",  new { page = 3 }, null)

Remembering that your actionLink "works" as follows:

MvcHtmlString HtmlHelper.ActionLink(
    string linkText, 
    string actionName, 
    string controllerName, 
    object routeValues, 
    object htmlAttributes

Roughly speaking, you first pass the text, then the Action , the Controller , the route values ​​and html attributes.

As you can see, in ActionLink "you don't care" about the routes, just call the Action and the Controller , remembering to pass the necessary parameters.

Scroll to Top