What is routing in MVC?

Posted by  Lee Patric
 299  View(s)
Rate this:
  1. What is routing in MVC?

    Routing helps you to define a URL structure and map the URL with the controller.

    Let us try to understand this with an example, - when we want that when a user types "http: // localhost / View / ViewCustomer /", it goes to the "Customer" controller and the DisplayCustomer action Invites you. This is defined by adding an entry into the routes collection using the map_route function. Below is the underlined code which shows how the URL structure and mapping with controller and action are defined.

                   "View", // Route name
                   "View/ViewCustomer/{id}", // URL with parameters
                   new { controller = "Customer", action = "DisplayCustomer",
    id = UrlParameter.Optional }); // Parameter defaults   

    And the route mapping code is written in "RouteConfig.cs" file and registered using "global.asax" application start event.