我創建了一個空的MVC4應用程序,所有的東西都工作正常,之後我添加一個區域到我的項目命名爲「主持人」。我區路由代碼是這樣的:MVC 4區域路由不起作用
using System;
using System.Web.Mvc;
namespace EskimoArt.Areas.Moderator
{
public class ModeratorAreaRegistration : AreaRegistration
{
public override string AreaName
{
get
{
return "Moderator";
}
}
public override void RegisterArea(AreaRegistrationContext context)
{
context.MapRoute(
"Moderator_default",
"Moderator/{controller}/{action}/{id}",
new {controller="Dashboard", action = "Index", id = UrlParameter.Optional }
);
}
}
}
而且我Global.asx代碼是這樣的:
using System.Web.Http;
using System.Web.Mvc;
using System.Web.Optimization;
using System.Web.Routing;
namespace EskimoArt
{
// Note: For instructions on enabling IIS6 or IIS7 classic mode,
// visit http://go.microsoft.com/?LinkId=9394801
public class MvcApplication : System.Web.HttpApplication
{
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
WebApiConfig.Register(GlobalConfiguration.Configuration);
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
RouteConfig.RegisterRoutes(RouteTable.Routes);
BundleConfig.RegisterBundles(BundleTable.Bundles);
}
}
}
但現在我要訪問的
> http://localhost/Moderator/Dashboard
它顯示了一個錯誤像這樣的頁
Server Error in '/' Application.
The resource cannot be found.
Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. Please review the following URL and make sure that it is spelled correctly.
Requested URL: /Moderator
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.17929
你在你的地區有沒有控制器? –
是的,我在我的區域有控制器。我通過下面的選項找出問題,就是調用AreaRegistration。RegisterAllAreas();在您的默認路線 –