路线:
routes.MapRoute(
"Items", // Route name
"{controller}/{action}/{id}", // URL with parameters
new {controller = "Item", action = "Index", id = UrlParameter.Optional} // Parameter defaults
);
htmlhelper:
@Html.ActionLink("Chairs", "List", "Item", new {id="Chairs"}, null)
它生成的链接:
http://localhost:57899/Item/List?id=Chairs
我希望它显示:
http://localhost:57899/Item/List/Chairs
怎么做?
答案 0 :(得分:0)
如果您尝试以下操作,而不是使用ActionLink会发生什么?
@Html.RouteLink("Items", new { id = "Chairs" })
答案 1 :(得分:0)
您调用Html.RouteLink(而不是Action Link)并在您的通用下映射其他路线,如下所示:
routes.MapRoute(
"ChairsRoute", // Route name
"Item/List/{id}", // URL with parameters
new {controller = "Item", action = "Index", id = UrlParameter.Optional} // Parameter defaults
);
当您呼叫RouteLink时,您只需传递“ChairsRoute”名称