Link to different controller and pass two values

99 views Asked by At

How do I create a link that goes to Controller/Action/Id/Application?

I have tried with

@Html.ActionLink("link", "action", "controller", new { Id = @Model.Id }, new { application = @application.Name})
1

There are 1 answers

0
Dave Bish On

First, you'll need to have a custom route defined in App_Start/RouteConfig.cs

Something like:

routes.MapRoute(
    name: "RouteName",
    url: "{controller}/{action}/{id}/{application}",
    defaults: new 
    {
        controller = "Home", 
        action = "Index", 
        id = UrlParameter.Optional, 
        application = UrlParameter.Optional 
    });

Then, to generate URLs:

@Html.ActionLink("link", "action", "controller", new { id = @Model.Id, application = @application.Name})