routing in asp.net mvc Options
routing in asp.net mvc Options
Blog Article
Contact MapControllerRoute or MapAreaControllerRoute, to map both of those conventionally routed controllers and attribute routed controllers.
We now have specified the default controller and action to take care of any URL request, which starts off from domainname/college students.
In the above mentioned example, We now have defined the Route Pattern controller / motion / id and also furnished the default values for controller, motion, and id parameters.
The motion benefits factory approaches such as RedirectToAction and CreatedAtAction observe a similar pattern to the strategies on IUrlHelper.
Just about every MVC application have to configure (sign up) a minimum of just one route configured from the MVC framework by default. You may sign up a route in RouteConfig class, which can be in RouteConfig.cs underneath App_Start folder. The subsequent figure illustrates how you can configure a route while in the RouteConfig course .
Extracts the route values controller = Goods, action = Facts, id = five by tokenizing the path. The extraction of route values ends in a match In case the application provides a controller named ProductsController and also a Aspects motion:
This allows us to create routes that count only about the URL values without having predetermined or default values. If a route parameter is absent from your URL, It'll be treated as lacking.
The defaults home sets default properties with the controller, motion and sets the id as optional. The default values are employed when no values for your attribute is handed. Legitimate URLs for this route are as an example:
As we could see, We've got described a completely new route that expects a classification parameter. Now when we offer Electronics being a parameter, we get yourself a properly filtered listing
In case the application is using the default standard route, the worth with the url variable will be the URL path string /UrlGeneration/Desired destination. This URL route is established by routing routing in asp.net mvc by combining:
You may try this as well by switching the URL while in the browser. In this example, it is , other than the port may very well be various.
Attribute routing supports defining several routes that get to the same action. The commonest usage of this is to imitate the actions in the default common route as shown in the next case in point:
In general, attribute routing selects the correct route with URL matching. When the default purchase used for URL generation isn't Operating, using a route identify being an override is frequently less difficult than making use of the Purchase home.
It offers a simple way to take care of usual routing eventualities with no need for in depth attribute routing.