How to remove controller name from URL in MVC project

前端 未结 4 1556
不思量自难忘°
不思量自难忘° 2020-12-12 05:43

I have a URL like below and I need to remove the controller name (myController). I\'ve use several fixes but none fixed the issue. Please help me guys..

http://fold

4条回答
  •  难免孤独
    2020-12-12 06:08

    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});
    
    routes.MapRoute("Default", "{controller}/{action}/{id}", new {controller = "Home", action = "Index", id = UrlParameter.Optional} );
    

提交回复
热议问题