How to use @Html.ActionLink to create links to a multi-route?

3

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

http://localhost:59278/video/categoria/new-movies/3

Being that my control is:

[Route("video/categoria/new-movies/{page?}")]
public async Task<ActionResult> Index(int? page)
{

}

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

    
asked by anonymous 05.11.2015 / 18:09

1 answer

2

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

routes.MapMvcAttributeRoutes();

Once you've done this, just add the attribute to your controller , just as you are doing.

[Route("video/categoria/new-movies/{page?}")]
public async Task<ActionResult> Index(int? page)
{

}

Until that part I suppose you already own, 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
)

The "rough way", first you pass the text, then the Action , Controller , route values and html attributes.

  

As you can see, in the% w / w you do not care about routes, just call Action and Controller , remembering to pass the required parameters.

    
05.11.2015 / 20:13