ASP.NET MVC 2 Areas, Strange routing behavior
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开发者_StackOverflow中文版 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 = "" }
);
}
}
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 }
);
精彩评论