articles

Home / DeveloperSection / Articles / MVC Routing

MVC Routing

MVC Routing

Hemant Patel2295 07-Sep-2017

Routing is way that eliminates needs of mapping each and every URL with a physical file. Routing provide a way that’s enable developer to define URL pattern that maps to the request handler. This request handler can be a file (In asp.net application, its .aspx file) or class (In MVC its Controller class and Action method).

For example, http//domain/Employee can be mapped to http://domain/EmployeeInfo.aspx in ASP.Net Web application. And http//domain//Employee same URL mapped with controller and action method in MVC.

                                  MVC Routing
 

Every MVC application must be configured by MVC framework by default. And also every MVC application must register(configure) at least one route. You can configure route in RouteConfig class, RouteConfig class is in RouteConfig.cs under App_Start directory(folder). Following line of code illustrate how to configure route in RouteConfig.cs file in MVC.

                            MVC Routing
 

In above line of code 'BasicTut' is Controller, “Index” is the Action method and, id is a parameter that can be optional.

We can also configure (register) custom a route by using the extension method of MapRoute.

At least two parameters require red in MapRoute. The Default parameter is optional.

 

You can also register multiple custom routes with different names. below of codes that illustrate how to register multiple route routes

                                       MVC Routing


Updated 22-Dec-2022
Exploring the online world is my passion. have experience of #content writing #SEO #Digital Marketing #On-Page #Lead Generation #Content Analyst #Marketing Analyst... I could never stop at one point, continuously wanted to acquire more and more skills. My work for any organization will be full of passion and hard work.

Leave Comment

Comments

Liked By