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 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 Action method and id is parameter that can be optional.

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

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

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

                                       MVC Routing

  Modified On Sep-07-2019 12:17:24 AM

Leave Comment