Routing finds a controller in my areas, but not views

I am trying to use the Maarten Balliauw Domain Route class to map subdomains to regions in an MVC2 application, so I have URLs like:

http://admin.mydomain.com/home/index

instead:

http://mydomain.com/admin/home/index

So far, I have only had partial success. Execution is routed to the right controller in the correct area, but then cannot find the correct view. I get the following error:

The view 'Index' or its master was not found. The following locations were searched:
~/Views/AdminHome/Index.aspx
~/Views/AdminHome/Index.ascx
~/Views/Shared/Index.aspx
~/Views/Shared/Index.ascx 

This tells me that MVC only looks for a view in the root views folder, and not in the views folder within the Area. If I copy the view from the Area Views folder to the root views folder, the page will look great. This, however, completely destroys the purpose of dividing the APP into Regions.

I define the route for the area as:

public class AdminAreaRegistration : AreaRegistration
{
    public override string AreaName
    {
        get { return "Admin"; }
    }

    public override void RegisterArea(AreaRegistrationContext context)
    {
        context.Routes.Add(
            "Admin_Default"
            , new DomainRoute(
                "admin.localhost"
                , "{controller}/{action}/{id}"
                , new { controller = "AdminHome", action = "Index", id = UrlParameter.Optional }
        ));
    }
}

, , .

+5
2

, . MVC 2 , , MVC. , IRouteWithArea. 'Area' RouteData, , , . DomainRoute, , , , .

:

 context.Routes.Add(
     "Admin_Default"
     , new DomainRoute(
         "admin.mydomain"
         ,"Admin"
         , "{controller}/{action}/{id}"
         , new { controller = "AdminHome", action = "Index", id = UrlParameter.Optional }
        ));
+3

, , , MapRoute.

, - Web, RegisterRoutes Global.asax.cs :

routes.MapRoute(
    "Default",
    "{controller}/{action}/{id}",        
    new { action = "Index", id = UrlParameter.Optional },
    null,
    new string[] { "Web.Controllers" }
);

RegisterArea moethod AdminAreaRegistration.cs :

context.MapRoute(
    "Admin_Default",
    "Admin/{controller}/{action}/{id}",
    new { action = "Index", id = UrlParameter.Optional },
    null,
    new string[] { "Web.Areas.Admin.Controllers" }
);
+1

All Articles