Any route templates defined to the controller are prepended to route templates to the actions. Placing a route attribute to the controller makes all actions within the controller use attribute routing.
To achieve this, we can configure the MapControllerRoute technique, as shown within the image beneath. Here, you'll be able to see We've got specified the pattern as Student/All and the default controller and motion identify as controller = College student, action = Index.
The route identify concept is represented in routing as IEndpointNameMetadata. The phrases route title and endpoint identify:
Routes might be established by adding them towards the RouteCollection or by decorating actions or controller with attributes.
Now you will notice a different C# file ProcessController.cs during the Controllers folder, that is open for editing in Visual Studio too.
As you could see in the above mentioned determine, the route is configured using the MapRoute() extension method of RouteCollection, exactly where name is "Default", url pattern is " controller / action / id " and defaults parameter for controller, motion approach and id parameter.
This permits us to build routes that depend only on the URL values without the need of predetermined or default values. If a route parameter is absent with the URL, It will probably be dealt with as missing.
Attribute dependent routing - to determine this type of routing, we specify the Route attribute while in the action technique of the controller.
The screenshot previously mentioned demonstrates a few routing in asp.net mvc different variations of a static segment during the route. The first route calls the ShowArchievePosts action inside the Posts controller in the event the person enters /Blog/Archive.
To obtain this, we are able to configure A different MapControllerRoute system, as proven within the underneath graphic. Below, you'll be able to see Now we have specified the pattern as StudentDetails/ ID and specified the default controller and action name as controller = College student”, action = Information.
To realize this, we can easily configure An additional MapControllerRoute strategy, as revealed in the beneath impression. In this article, you are able to see We've got specified the pattern as controller / action / id:int? and specified the default controller and action title as controller = Household, motion = Index.
Put into action IRouteTemplateProvider to define tailor made route attributes. Just about every IRouteTemplateProvider allows you to determine one route using a custom route template, get, and name:
It may also be combined like this "C/ controller / motion / id ". In this case, the url must appear to be under
It is possible to surely incorporate your own personal routes. If you don't like these motion names, When you've got distinctive ID parameters or if you merely usually have a special URL structure for your web site, You'll be able to incorporate your own personal route entries.