如何{controller}/{id}
在 ASP.NET MVC 5 中设置路由。我想实现的目标:如果没有{action}
定义,请Index()
使用id
.
我试过thism但没有用:
// Keep default routing
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
// Add own routing in case of missing "action"
routes.MapRoute(
name: "Controller/Id",
url: "{controller}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);