链接到不同的控制器并传递两个值

时间:2015-06-16 13:25:03

标签: c# html asp.net-mvc actionlink

如何创建转到Controller / Action / Id / Application的链接?

我试过

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

1 个答案:

答案 0 :(得分:1)

首先,您需要在App_Start/RouteConfig.cs

中定义自定义路线

类似的东西:

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

然后,生成网址:

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