我一直试图让几个自定义路线没有运气。我的汽车应用程序有两个页面。第一页显示车辆列表。当用户单击此页面上生成的链接时,会将它们带到产品列表页面。问题是此页面无法正确生成链接。
以下是路线:
routes.MapRoute(
"Select_Vehicle",
"Select_Vehicle/{id}/{make}",
new { controller = "Select_Vehicle", action = "Index", id = UrlParameter.Optional, make = UrlParameter.Optional });
routes.MapRoute(
"Products",
"Products/{id}/{make}/{model}",
new { controller = "Products", action = "Index", id = UrlParameter.Optional, make = UrlParameter.Optional, model = UrlParameter.Optional });
routes.MapRoute(
"Default",
"{controller}/{action}/{id}",
new { controller = "Home", action = "Index", id = UrlParameter.Optional });
Select_Vehicle 页面应生成如下链接:
/products/horns/dodge/dakota
但我得到的是:
/Products/Index/horns?make=dodge&model=Dakota
它只是无法正常工作。另外,我不明白为什么“索引”也会显示,因为它是默认设置。
我已经尝试过 ActionLink 和 RouteLink:
@Html.RouteLink(model, new { Controller = "Products", id = Model.CategoryName, make = Model.CurrentMake, model = model })
@Html.ActionLink(model, "Index", "Products", new { id = Model.CategoryName, make = Model.CurrentMake, model = model }, null)
这真让我抓狂。