8

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?

CMircea
  • 3,543
  • 2
  • 36
  • 58

1 Answers1

6

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.

jd4u
  • 5,789
  • 2
  • 28
  • 28
  • 1
    There is no `Order` property on `RouteAttribute`, only Name. – CMircea Oct 31 '13 at 13:56
  • 4
    in the meanwhile there is one (Checked with mvc 5.2.2) -> http://msdn.microsoft.com/en-us/library/system.web.mvc.routeattribute.order(v=vs.118).aspx – Boas Enkler Sep 15 '14 at 11:14