Interviews - C# Corner

Amita Palkar - Junnarkar
Explain Routing in MVC
By Amita Palkar - Junnarkar in .NET onMar 23 2018
  • Mahesh Pattar
    Apr, 2018 10

    Hello Friends, Lets learn about how routing works MVC framework. Each and every application has routing mechanism inside framework when request come from browser to application.Having said that let's understand how routing mechanism built in MVC (Model View Controller) .Step by Step explanation.1. RequestUser makes request from browser to the mvc app. Request should have controller name and action name and id is optional. Ex. http://servername:port/controller/action2. RoutingRequest will be validated with Route table which will have collection of routes defined in application (controller name and action name). If the received request doesn't match returns 404 Not found error else handovers the request to next step.3. MVC InitializerMVC intializer will gets the request and creates the instance of respective controller and passes request to controller.4. ControllerOnce controller receives the requests it executes the respective action method.5. Action Executionaction method will inturn communicates with Business Layer -> Data Access Layer and get the data and passed to View Engines.6. View EngineIts responsibility to prepare the data based on return types (JsonResult, JavaScriptResult etc) and sends to View Result7. ViewResultGets the data from View Engines and sends to respective view to render on the browser.8. ViewRenders the result on specified view9. ResponseUser gets required data on browser page as response.Thanks for your time and reading the article.I hope its very clear to read and understand. If you have any question please reply.

    • 6
  • Mahesh Pattar
    Apr, 2018 10

    Hello Friends, Lets learn about how routing works MVC framework. Each and every application has routing mechanism inside framework when request come from browser to application.Having said that let's understand how routing mechanism built in MVC (Model View Controller) .Step by Step explanation.1. RequestUser makes request from browser to the mvc app. Request should have controller name and action name and id is optional. Ex. http://servername:port/controller/action2. RoutingRequest will be validated with Route table which will have collection of routes defined in application (controller name and action name). If the received request doesn't match returns 404 Not found error else handovers the request to next step.3. MVC InitializerMVC intializer will gets the request and creates the instance of respective controller and passes request to controller.4. ControllerOnce controller receives the requests it executes the respective action method.5. Action Executionaction method will inturn communicates with Business Layer -> Data Access Layer and get the data and passed to View Engines.6. View EngineIts responsibility to prepare the data based on return types (JsonResult, JavaScriptResult etc) and sends to View Result7. ViewResultGets the data from View Engines and sends to respective view to render on the browser.8. ViewRenders the result on specified view9. ResponseUser gets required data on browser page as response.Thanks for your time and reading the article.I hope its very clear to read and understand. If you have any question please reply.

    • 3
  • Aniket Rana
    Apr, 2018 3

    http://www.tutorialsteacher.com/mvc/routing-in-mvc

    • 3
  • Deepak Verma
    May, 2018 21

    Basically, Routing is a pattern matching system that analyzes the incoming request and figures out what to do with that request. At runtime, Routing engine uses the Route table for matching the incoming request URL pattern against the URL patterns defined in the Route table. You can register one or more URL patterns in the Route table at Application_Start event of your project. When the routing engine finds a match in the route table for the incoming request URL, it forwards the request to the appropriate controller and action. If there is no match found in the route table for the incoming request URL, it returns a 404 HTTP status code that means "Page Not Found".

    • 2
  • Mahesh Pattar
    Apr, 2018 10

    Hello Friends, Lets learn about how routing works MVC framework. Each and every application has routing mechanism inside framework when request come from browser to application.Having said that let's understand how routing mechanism built in MVC (Model View Controller) .Step by Step explanation.1. RequestUser makes request from browser to the mvc app. Request should have controller name and action name and id is optional. Ex. http://servername:port/controller/action2. RoutingRequest will be validated with Route table which will have collection of routes defined in application (controller name and action name). If the received request doesn't match returns 404 Not found error else handovers the request to next step.3. MVC InitializerMVC intializer will gets the request and creates the instance of respective controller and passes request to controller.4. ControllerOnce controller receives the requests it executes the respective action method.5. Action Executionaction method will inturn communicates with Business Layer -> Data Access Layer and get the data and passed to View Engines.6. View EngineIts responsibility to prepare the data based on return types (JsonResult, JavaScriptResult etc) and sends to View Result7. ViewResultGets the data from View Engines and sends to respective view to render on the browser.8. ViewRenders the result on specified view9. ResponseUser gets required data on browser page as response.Thanks for your time and reading the article.I hope its very clear to read and understand. If you have any question please reply.

    • 2
  • Bhairab Dutt
    May, 2018 16

    Hi Friends, Routing is the concepts which help the user to move from one view to another . In MVC We have RouteConfig.cs within the APP Start folder which maintain the routing in MVC. Fo example when user request any page from the browser by enter the url then the routeconfig will match the route using map.route . Here Default Route and specified route details which work according to Controller name and Action method name . The parameter either optional or mandatory which we will define during routing creation.

    • 1
  • Sankara Krishnan Venugopal
    Apr, 2018 27

    ASP.NET routing was initially launched as MVC routing to support clean URL semantics for sites built on ASP.NET MVC. However, it was later pushed up in the framework to become a part of ASP.NET core and thus available for WebForms as well. In this article, we look at how routes work and how you can use them in your MVC web application to expose functionality in a transparent and discoverable way.

    • 1
  • Amit Kumar Agrawal
    Apr, 2018 13

    Atleast one routing path is defined by MVC framework. You can register a route in RouteConfig class, which is in RouteConfig.cs under App_Start folder.Route is configured using the MapRoute() extension method of RouteCollection, where name is "Default", url pattern is "{controller}/{action}/{id}" and defaults parameter for controller, action method and id parameter. Defaults specifies which controller, action method or value of id parameter should be used if they do not exist in the incoming request URL.After configuring all the routes in RouteConfig class, you need to register it in the Application_Start() event in the Global.asax.

    • 1
  • Satish Kumar Vadlavalli
    Apr, 2018 4

    https://www.c-sharpcorner.com/UploadFile/3d39b4/routing-in-mvc/

    • 1
  • Abhijit Sahoo
    Jul, 2018 4

    In the ASP.NET Web Forms application, every URL must match with a specific .aspx file. For example, a URL http://domain/studentsinfo.aspx must match with the file studentsinfo.aspx that contains code and markup for rendering a response to the browser. Route Route defines the URL pattern and handler information. All the configured routes of an application stored in RouteTable and will be used by Routing engine to determine appropriate handler class or file for an incoming request. Configure a Route Every MVC application must configure (register) at least one route, which is configured by MVC framework by default. You can register a route in RouteConfig class, which is in RouteConfig.cs under App_Start folder.

    • 0
  • Shivam Shukla
    Jun, 2018 27

    Basically, Routing is a pattern matching system that monitor the incoming request and figure out what to do with that request. At runtime, Routing engine use the Route table for matching the incoming request's URL pattern against the URL patterns defined in the Route table. You can register one or more URL patterns to the Route table at Application_Start event. MVC5 also supports attribute routing, to know more refer

    • 0
  • Sreekanth Reddy
    Jun, 2018 4

    MVC routes are initialized at RouteConfig.cs with RegisterRoutes method, where we are accessing the configuration at Application_Start in global.asax file.

    • 0

Most Popular Companies

Most Popular Job Functions

MOST LIKED QUESTIONS