asp.net MVC

What is Routing in asp.net mvc?

What is Routing in asp.net mvc?, someone asked me to explain?

Routing is nothing but simply your mvc url. What mean is that simply your url. for example some developers using some kinds of prefix name cls with class name and also given method name as their own idea. These kinds of things definitely end user will not understand for rectify those problem we have to use routing in mvc. 

routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

            routes.MapRoute(

                name: "Default",

                url: "{controller}/{action}/{id}",

                defaults: new { controller = "Home", action= "Index", id = UrlParameter.Optional }

            );

 

Description:

Routes is route collection and MapRoute is method name for routes. MapRoute have three arguments like name, url and defaults. Here name is key name and its unique.

IgnoreRoute methods used to do not allow user to invoke such kind of file .axd 

routes.MapRoute(

                name: "Home",

                url: "",

                defaults: new { controller = "Employee", action= "Index", id = UrlParameter.Optional }

            );

 

Here when I build the application it will automatically call Index view with in Employee Controller. Please remember one thing default name unique will come last why because if you set default name as first none of your  matching url will not execute.

Post your comments / questions