5 Easy Facts About routing in asp.net mvc Described
5 Easy Facts About routing in asp.net mvc Described
Blog Article
After the person entered a URL, ASP.Internet searches through the RouteCollection until eventually it finds a fitting route. A fitting route would not indicate that it causes the result which the person expects.
Working with website page for a route parameter with attribute routing is a standard error. Doing that results in inconsistent and complicated behavior with URL technology.
Inside the preceding code, the Index system templates will have to prepend / or ~/ to the route templates. Route templates placed on an motion that begin with / or ~/ Never get combined with route templates placed on the controller.
Routing in ASP.NET Main MVC is usually a system that inspects the incoming HTTP ask for (i.e., URLs) and after that maps those HTTP requests to the right controller steps. It enables the framework to determine what code to execute based on the URL of the request.
The subsequent case in point configures MVC to utilize the default regular route and a location route for a region named Web site:
As it is possible to see in the above mentioned determine, the route is configured utilizing the MapRoute() extension means of RouteCollection, wherever identify is "Default", url sample is " controller / motion / id " and defaults parameter for controller, action system and id parameter.
Utilizing the preceding controller definition and route template, the HomeController.Index action is run for the following URL paths:
Nearly anything just after "localhost:1234/" could well be regarded as a controller identify. A similar way, just about anything once the controller identify might be regarded as action name and then the worth of id parameter.
The standard default route handles routes extra succinctly. Having said that, attribute routing makes it possible for and needs specific control of which route templates apply to each action.
The preceding code is undoubtedly an case in point or poor routing design and style. It had been utilised to illustrate the Buy property.
I uploaded the supply code to GitHub in order to down load it and Enjoy a tad around with distinctive routes.
Numerous standard routes may be configured by adding more phone calls to MapControllerRoute and MapAreaControllerRoute. Doing this allows defining multiple conventions, or to introducing common routes that happen to be committed to a specific motion, for instance:
Most apps must decide on a simple and descriptive routing plan to ensure that URLs are readable and significant. The default conventional route controller=Property / motion=Index / id? :
It’s a very good observe to offer Just about every routing in asp.net mvc route a singular title. This assists when producing URLs based on route names. You can specify controller, motion, and parameter default values. This is helpful for defining fallbacks for lacking elements of the route.