我有 Action
public virtual ActionResult Show(string userId)
和
public virtual ActionResult Show(int groupId)
在 Global.asax 中我有
routes.MapRoute(
"Group_Default",
"{controller}/{action}/{groupId}",
MVC.Groups.Show()
);
routes.MapRoute(
"UserProfile_Default",
"{controller}/{action}/{userId}",
MVC.Profile.Show()
);
现在,当我请求 group/show/...
时,它工作正常。但是当我调用 Profile/Show/...
时,参数为空。但是,如果我删除 UserProfile_Default
那么两者都有效,但配置文件 URL 包含参数的问号(我希望它像 .../profile/show/5678
一样干净)
一条路线以某种方式阻挡了另一条路线。
最佳答案
试试这些:
routes.MapRoute(
"Group_Default",
"Group/{action}/{groupId}",
new { controller = "Group" }
);
routes.MapRoute(
"UserProfile_Default",
"Profile/{action}/{userId}",
new { controller = "Profile" }
);
为了将来引用,路由调试器是一个非常好的工具,可以准确地查看您的路由发生了什么以及哪些 URL 正在执行哪些操作:http://haacked.com/archive/2008/03/13/url-routing-debugger.aspx
关于c# - T4MVC - 不同的 Controller 冲突,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10253278/