ASP.NET MVC Route Registration and Areas
July 9, 2010
I need to be able to register a route via an instance of RouteCollection to an area. I couldn’t put it in the normal area route registration as it had to be registered last. It took a while to figure out that this works:
1
2
3
4
5
6
7
8
9
10
11
public static void RegisterAreaRoute(RouteCollection routes) {
routes.MapRoute(
"MyRouteName",
"{*path}",
new
{
// options
},
new[] { "_Namespace_.Areas._Area_Name_.Controllers" }
).DataTokens.Add("area", _Area_Name_);
}
Categories:
ASP.NET MVC