0

我刚刚启动了 MVC,我可以将一个 ID 传递给一个页面,但似乎无法让我的路由使用两个参数。有谁知道为什么?

这是我的代码:

全球的:

 routes.MapRoute(
           "Default", // Route name
           "{controller}/{action}/{id}", // URL with parameters
           new { controller = "Account", action = "Login", id = UrlParameter.Optional } 
       ); 




    routes.MapRoute(
    "EditVoucher",                                              // Route name
    "{controller}/{action}/{id}/{userid}",                           // URL with parameters
    new { controller = "Admin", action = "EditVoucher", id = "", userid = "" }  // Parameter defaults
    );     


**My controller:**  

[HttpGet]
 public ActionResult EditVoucher(int ID, int UserID)
 {
}


**my link:**

 @Html.ActionLink("[Edit]", "EditVoucher", new { Controller = "Admin", id = item.ID, userid = 2 })  



this passes through the values fine but I end up with this sort of URL:

**/Admin/EditVoucher/2?userid=2**

thanks
4

1 回答 1

3

ActionLink将使用可以满足您的参数的第一条路线。

由于第一个(默认)路由也满足您的参数,因此您需要将自定义路由放在首位。

于 2012-05-04T12:53:13.560 回答