Interchange Controller and action place in URL for MVC application

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
  1. routes.MapRoute(  
  2.                name: "Default",  
  3.                url: "{controller}/{action}/{id}",  
  4.                defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }  
  5.            );  
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.
  1. routes.MapRoute(  
  2.                name: "Default",  
  3.                url: "{action}/{controller}/{id}",  
  4.                defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }  
  5.            );  
Now all your action name will be placed before controller name in URL.
 
Ebook Download
View all
Learn
View all