What is routing in MVC?


 What is routing in MVC?

mvc routing

Route-

Route defines the URL pattern and handler information. All the configured routes of an application stored in RouteTable and will be used by the Routing engine to determine the appropriate handler class or file for an incoming request.

This RouteCollection is actually a property of RouteTable class.

Routing in MVC -

Routing enables us to define a URL pattern that maps to the request handler. This request handler can be a file or class.

 In ASP.NET Webform application, request handler is .aspx file and in MVC, it is Controller class and Action method.

{controller}/{action}/{id}".  -URL pattern starts after the domain name.

What are the TYpes of Routing supported by ASP.NET MVC?

MVC application can define routes in two ways -

1. Convention Based Routing 

2. Attribute-Based Routing

The Routing functionality is implemented in the System.Web.Routing.

MVC Routing

Multiple Routes -

You can also configure a custom route using the MapRoute extension method. 

You need to provide at least two parameters in MapRoute, route name and URL pattern. The Defaults parameter is optional.

You can register multiple custom routes with different names.

Route constraints apply restrictions on the value of parameters.

The route must be registered in the Application_Start event in Global.ascx.cs file.


This was an introductory article for beginner's to make them learn the concept of  Routing in the ASP.NET MVC application. I hope this has been a little informative. 

If you wish to learn more about routes, navigate to ASP.NET MVC Routing Overview in Microsoft docs.

If you found this article useful, share it.*

 SoftCodeLearner: ASP.NET Interview questions and answers

SoftCodeLearner: ASP.NET MVC - Model View Controller

Umesh Mahajan | Facebook


No comments:

Post a Comment