Reputation: 3568
In older MVC versions, with the AttributeRouting library, I can have multiple routes and specify a precedence, so the most appropriate is picked when generating URLs:
[Route("", ActionPrecedence = 1)]
[Route("city/{citySlug}", ActionPrecedence = 2)]
In MVC 5 there is no ActionPrecedence
property on the attribute. How do I specify the route precedence in that case?
Upvotes: 8
Views: 5708
Reputation: 5807
Are you using release version?
In Released version MVC 5.0, you can specify Name
and Order
for every Route
. The Order
is helpful in Url generation.
Route(template, NamedParams:[Name,Order])
[Route("city/{id}",Name="CityFirst", Order=1)]
[Route("mycity/{id}", Name = "MyCityFirst", Order = 2)]
Refer : Attribute Routing in ASP.NET MVC 5
UPDATE: My mistake! above answer was based on the RC1 assumed to be Released version.
In released version, there is no named attribute "Order".
Order of attribute is calculated based on the precedence of Route Template matching.
Upvotes: 6