Removing Controller from url in a specific scenario

穿精又带淫゛_ 提交于 2019-12-02 11:22:56

You should map new route in the global.asax (add it before the default one), for example:

routes.MapRoute("SpecificRouteforHomeController", "{action}/{id}", new {controller = "Home", action = "Index", id = UrlParameter.Optional});

// default route  any defalt you want
routes.MapRoute("Default", "{controller}/{action}/{id}", new {controller = "Account", action = "Login", id = UrlParameter.Optional} );
 routes.MapRoute(
 name: "Default",
 url: "{controller}/{action}/{id}",
 defaults: new { controller = "DefaultControllerName", action = "Index", id = UrlParameter.Optional }
    );

If u will specify the controller name then this will work with that controller name. Bu if not the by default it will take controller name as DefaultControllerName.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!