Explain what is routing in MVC? What are the three segments for routing important?

Category: C SharpExplain what is routing in MVC? What are the three segments for routing important?
Editor">Editor Staff asked 2 years ago

Explain what is routing in MVC? What are the three segments for routing important?

1 Answers
Editor">Editor Staff answered 2 years ago

Routing is a mechanism to process the incoming URL that is more descriptive and gives the desired response. In this case, URL is not mapped to specific files or folder as was the case of earlier days web sites.
 
There are two types of routing (after the introduction of ASP.NET MVC 5).

  1. Convention-based routing – to define this type of routing, we call MapRoute method and set its unique name, URL pattern and specify some default values.
     
  2. Attribute-based routing – to define this type of routing, we specify the Route attribute in the action method of the controller.

Routing is the URL pattern that is mapped together to a handler,routing is responsible for incoming browser request for particular MVC controller. In other ways let us say routing help you to define a URL structure and map the URL with controller. There are three segments for routing that are important,

  1. ControllerName
  2. ActionMethodName
  3. Parammeter

Code Example
 
ControllerName/ActionMethodName/{ParamerName} and also route map coding written in a Global.asax file.