Home > MVC > Routing in MVC

Routing in MVC

ASP.MVC routing module is responsible for handling incoming browser request (http request) and map to MVC controller action method.

Routing Module

  • When first time request come to the MVC application, it check for ‘Route Table’ since it is first time request to the application it fills the ‘Route Table‘.
  • Once the ‘Route Table’ is updated then request goes to ‘URL Routing Module’. If the incoming request not first one then it directly goes to ‘URL Routing Module’.
  • And this ‘Routing table’ is created at Application_Start event.
    “RegisterRoutes(RouteTable.Routes);”

routes.MapRoute(
“Default”,                                              // Route name
“{controller}/{action}/{id}”,                           // URL with parameters
new { controller = “Home”, action = “Index”, id = “” }  // Parameter defaults
);

Name: Default
URL Pattern: {controller}/{action}/{id}
Values: new { controller = “Home”, action = “Index”, id = “” }

  • Depending on the URL sent “UrlRoutingModule” searches the route table to create “RouteData” object which has the details of which controller and action to invoke.
  • From ‘URLRoutingModule’ it goes to ‘MVCHandler’ as RequestContext object, the ‘RouteData’ object is used as RequestContext object.
  • In ‘MVCHandler‘ Controller instance will be created and it calls the ‘Execute‘ method of the controller class.
  • Once ‘ActionMethod‘ executed result will be sent back to view as response object.

Note:-
Routing module is responsible till it calls the matching ActionMethod.

 

Advertisements
Categories: MVC Tags:
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: