ASP.NET MVC - 从URL中删除控制器名称 [英] ASP.NET MVC - Removing controller name from URL
本文介绍了ASP.NET MVC - 从URL中删除控制器名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想从我的网址删除控制器名称(对于一个特定的控制器)。例如:
I want to remove the controller name from my URL (for one specific controller). For example:
http://mydomain.com/MyController/MyAction
我希望这个网址更改为:
I would want this URL to be changed to:
http://mydomain.com/MyAction
我会如何在MVC这样做呢?我使用MVC2如果这能帮助我反正。
How would I go about doing this in MVC? I am using MVC2 if that helps me in anyway.
推荐答案
您应该在Global.asax(默认的前加入),映射新的路径,例如:
You should map new route in the global.asax (add it before the default one), for example:
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 - 从URL中删除控制器名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文