我正在尝试设置自定义路线,例如Admin/Settings/{action}/{id}
routes.MapRoute(
name: "AdminSettings",
url: "Admin/Settings/{action}/{id}",
defaults: new {
controller = "Settings", action = "Index", id = UrlParameter.Optional
}
);
我想要
Admin/Settings
- 控制器是设置和操作索引
和
Admin/Settings/Mail
控制器是设置和操作邮件
如何解决此问题以实现此路线?
答案 0 :(得分:0)
确保在默认路由之前将此路由添加到路径集合。否则,两个网址都会映射到默认路由{controller}/{action}/{id}
。在第一种情况下,你将有
// Admin/Settings
controller = "Admin", action = "Settings"
在第二种情况下
// Admin/Settings/Mail
controller = "Admin", action = "Settings", id = "Mail"