我想从我的 URL 中删除 Controller 名称(针对一个特定 Controller )。例如:
http://mydomain.com/MyController/MyAction
我希望将此网址更改为:
http://mydomain.com/MyAction
我该如何在 MVC 中做到这一点?如果这对我有帮助的话,我正在使用 MVC2。
最佳答案
您应该在global.asax中映射新路由(将其添加在默认路由之前),例如:
routes.MapRoute("SpecificRoute", "{action}/{id}", new {controller = "MyController", action = "Index", id = UrlParameter.Optional});
// default route
routes.MapRoute("Default", "{controller}/{action}/{id}", new {controller = "Home", action = "Index", id = UrlParameter.Optional} );
关于asp.net-mvc - ASP.NET MVC - 从 URL 中删除 Controller 名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3337372/