views:

135

answers:

1

I've created an Area named "Admin". I've created also a controller(Pages) and a view(List) in this areas.

When I run my app and enter the url "/Admin/Pages/List" I'm getting an The resource cannot be found error.

When I enter /Pages/List, the Action method is hit but the view is not found,because the app is searching in wrong directories

~/Views/Pages/List.aspx ~/Views/Pages/List.ascx ~/Views/Shared/List.aspx ~/Views/Shared/List.ascx

the view is in /Admin/Pages/List.

My routing conf for Admin area:

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

    public override void RegisterArea(AreaRegistrationContext context)
    {
        context.MapRoute(
            "Admin_default",
            "Admin/{controller}/{action}/{id}",
            new { controller= "Pages",action = "Index", id = "" }
        );
    }
}
+2  A: 

Have you added AreaRegistration.RegisterAllAreas(); to the Global.asax.cs

This should run before your existing routes.MapRoute calls

Edit:

Just looked at my Admin Area and the routing looks like this:

context.MapRoute(
                "Admin_Default",
                "Admin/{controller}/{action}/{id}",
                new { action = "Index", id = UrlParameter.Optional }
            );
Mark Redman
Yes,it's there.But it's not working anyway. Do I understant the routing right ? The url for areas should look like www.domain.com/Area/Controller/Action/Parameter ?
@user137348: Thats looks correct...
Mark Redman
Never mind. I found what causes the strange behavior. Earlier I copied the controller from the root to the area just using drag and drop. The unchanged namespace causes the problem. My bad. Anyway thanks for your time..