次の方法で共有


Change the default route in ASP.NET MVC

Hello folks,

As we know that ASP.NET MVC by default takes following setting available in RouteConfig file (under App_Start folder).

 routes.MapRoute(
                name: "Default",
                url: "{controller}/{action}/{id}",
                defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
            );

This means when you run the application, Home controller will be invoked and it's Index method will be executed by taking parameter id (if any).

you can change this behavior, if it's making sense to you.

For example if you want to invoke Store controller and It's Browse method while loading the application, you just need to change few things (controller and action values) as below.

routes.MapRoute(
                name: "Default",
                url: "{controller}/{action}/{id}",
                defaults: new { controller = "Store", action = "Browse", id = UrlParameter.Optional }
            );

Optionally you may also change the id parameter but I would personally recommend not to change (to keep it generic) unless there is some unavoidable reason.

Look forward for your comments!!