Cymen's Blog

ASP.NET MVC Route Registration and Areas

leave a comment

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:

public static void RegisterAreaRoute(RouteCollection routes) {
    routes.MapRoute(
        "MyRouteName",
        "{*path}",
        new
        {
            // options
        },
        new[] { "_Namespace_.Areas._Area_Name_.Controllers" }
    ).DataTokens.Add("area", _Area_Name_);
}

Written by Cymen

July 9th, 2010 at 5:09 pm

Posted in ASP.NET MVC

Leave a Reply