ASP.NET MVC area namespace problem

三世轮回 提交于 2019-12-22 04:37:30

问题


I create a new area in my asp.net mvc 3 solution named admin. Visual studio automatically assign the names space:

MyApp.areas.admin.controllers

I change this to MyApp.admin.controllers

But it stops resolving the action.
Any help in this regard will be appreciated.
Thanks


回答1:


You need to specify the new namespace when registering the route for your admin area.

In your \Areas\admin\adminAreaRegistration.cs file, you need to modify the RegisterArea() method as follows:

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/asp-net-mvc-area-namespace-problem

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!