In MVC you can change controller and action location in URL by doing some changes in RouteConfig.cs.
For e.g. In your application if Home is controller name and Index is action name so by default URL created to access it will be
http://localhost:4377/home/index
And RouteConfig.cs Setting will be
- routes.MapRoute(
- name: "Default",
- url: "{controller}/{action}/{id}",
- defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
- );
But if you want your URL to look like below.
http://localhost:4377/index/home
Only you have to do is to change RouteConfig.cs settings.
The only change will be action is placed before controller in URL parameter.
- routes.MapRoute(
- name: "Default",
- url: "{action}/{controller}/{id}",
- defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
- );
Now all your action name will be placed before controller name in URL.