routing in asp.net mvc Can Be Fun For Anyone
routing in asp.net mvc Can Be Fun For Anyone
Blog Article
Since an attribute route applies to a selected action, It is easy to produce parameters needed as Element of the route template definition. In the subsequent illustration, id is necessary as A part of the URL route:
Yet another probability to include a static component to your route would be to prefix the controller or motion as Portion of its title.
The worth of controller and action are Element of both equally ambient values and values. The tactic Url.Action generally uses the current values of action and controller and generates a URL route that routes to The present motion.
You will note an HTTP 404, because the routing motor is looking for ProcessController, which is not available.
Routing is usually a system to system the incoming url that is certainly much more descriptive and provides ideal response. In this case, URL will not be mapped to certain documents or folder as was the situation of previously times Web pages.
Regular routing can make use of a Particular sort of route definition referred to as a dedicated typical route. In the following instance, the route named site is usually a committed typical route:
Utilizing areas enables an app to get a number of controllers Along with the exact name, assuming that they've got diverse parts. Working with parts makes a hierarchy for the objective of routing by introducing An additional route parameter, region to controller and action.
The value of controller and motion are Component of the two ambient values and values. The method Url.Motion often uses The existing values of motion and controller and generates a URL path that routes to The present action.
Likewise, if we situation a request into the /Household/Facts/two URL, then the small print motion way of the Home Controller class will deal with the ask for, as demonstrated during the graphic underneath. Here, the parameter worth two is instantly mapped into the id parameter of the Details action method.
The [Region] attribute is exactly what denotes a controller as Component of a place. This controller is within the Blog space. Controllers without the need of an [Location] attribute will not be associates of any area, and don't match when the world route value is furnished by routing.
To create attribute routing significantly less repetitive, route characteristics over the controller are coupled with route characteristics on the person actions.
Attribute routing supports defining many routes that reach the exact action. The most typical use of this is to mimic the habits from the default regular route as shown in the next example:
Simplicity: It lessens the need to outline routes explicitly for every motion method or controller; as a substitute, it makes use of default conventions.
Usually, routes with locations need to be placed before as They are far more specific than routes devoid of an area. Committed conventional routes with routing in asp.net mvc catch-all route parameters like *posting could make a route far too greedy, meaning that it matches URLs that you just meant to be matched by other routes. Set the greedy routes later while in the route desk to circumvent greedy matches.