2
Reply

What is routing in MVC?

Chinmaya Dash

Chinmaya Dash

8y
1.5k
1
Reply

    Routing is a mechanism in MVC that decides which action method of a controller class to execute. Without routing there's no way an action method can be mapped. to a request. Routing is a part of the MVC architecture so ASP.NET MVC supports routing by default.

    Routing helps you to define a URL structure and map the URL with the controller.For instance let’s say we want that when a user types “http://localhost/View/ViewCustomer/”, it goes to the “Customer” Controller and invokes the DisplayCustomer action. This is defined by adding an entry in to the routes collection using the maproute function. Below is the underlined code which shows how the URL structure and mapping with controller and action is defined.routes.MapRoute("View", // Route name"View/ViewCustomer/{id}", // URL with parametersnew { controller = "Customer", action = "DisplayCustomer", id = UrlParameter.Optional }); // Parameter defaults