Asp.net

ASP.NET MVC 區域命名空間問題

  • July 19, 2011

我在我的 asp.net mvc 3 解決方案中創建了一個名為admin的新區域。Visual Studio 自動分配名稱空間:

MyApp.areas.admin.controllers

我把它改成MyApp.admin.controllers

但它會停止解決該操作。

在這方面的任何幫助將不勝感激。

謝謝

在為您的管理區域註冊路由時,您需要指定新的命名空間。

在您的 \Areas\admin\adminAreaRegistration.cs 文件中,您需要修改 RegisterArea() 方法,如下所示:

public override void RegisterArea(AreaRegistrationContext context)
{
   context.MapRoute(
       "admin_default",
       "admin/{controller}/{action}/{id}",
       new { action = "Index", id = UrlParameter.Optional }, 
       new string[] { "MyApp.admin.Controllers" }  // specify the new namespace
   );
}

引用自:https://stackoverflow.com/questions/6752644