我希望我的网址使用约定:
/{controller}/{id}/{action}
而不是
/{controller}/{action}/{id}
我尝试按如下方式设置路线:
routes.MapRoute(
"Campaign",
"{controller}/{action}/{id}",
new { controller = "Campaign", action = "Index", id = UrlParameter.Optional }
);
但这不起作用,因为我无法使id参数可选。
以下网址可以运作:
/campaign/1234/dashboard
/campaign/1234/edit
/campaign/1234/delete
但这些网址不:
/campaign/create
/campaign/indexempty
MVC只为两者调用Index
。我做错了什么?
答案 0 :(得分:7)
我认为您可能需要两条不同的路线。
routes.MapRoute(
"CampaignDetail",
"{controller}/{id}/{action}",
new { controller = "Campaign", action = "Index" }
);
routes.MapRoute(
"Campaign",
"{controller}/{action}",
new { controller = "Campaign", action = "Index" }
);