AttributeRouting for MVC
AttributeRouting is a fantastic open source Nuget package which allows you to specify routes using attributes on your MVC controllers and actions. We use it in all of our MVC projects at work and I highly recommended it, saves you having to map all y.
The QuickStart Guide can be found here.
Main reasons to use AttributeRouting
•Decorate your actions with GET, POST, PUT, DELETE, and verb agnostic attributes.
•Map multiple routes to a single action, ordering them with an Order property.
•Specify route defaults and constraints inline and also using attributes.
•Specify optional params inline with a token before or after the parameter name.
•Specify the route name for supporting named routes.
•Define MVC areas on a controller or base controller.
•Group or nest your routes together using route prefixes applied to a controller or base controller.
•Support legacy urls.
•Set the precedence of routes among the routes defined for an action, within a controller, and among controllers and base controllers.
•Generate lowercase outbound urls automatically.
•Define your own custom route conventions and apply them on a controller to generate the routes for actions within the controller without boilerplate attributes (think RESTful style).
•Debug your routes using a supplied HttpHandler.
Go check it out you wont be disappointed.
[…] AttributeRouting for MVC Gregor Suttie […]
[…] Attribute routing for MVC – Remove any routing concerns/issues and start using this now. […]
Amazing package. What i really liked is that you have control over your routes easily and in a pretty good way. Can’t wait to try it.
I like AttributeRouting but can’t seem to get unit testing to work for it. Is this something you’ve played around with?
Hi Jim
What issues are you facing? – I’ll try and think how to resolve them, Gregor.
Hi, thanks for your help.
I cannot seem to populate the route collection from a test project, at most i only end up with the default ignoreroute {resource}.axd.
I have added a testmethod with the following :-
var routes = new RouteCollection();
MvcApplication.RegisterRoutes(routes);
TestingGroundMVC.App_Start.AttributeRouting.RegisterRoutes(routes);
routes.MapAttributeRoutes();
routes.MapAttributeRoutes(x => x.ScanAssemblyOf());
https://github.com/mccalltd/AttributeRouting/wiki/Using-AttributeRouting-Outside-of-Web-Projects