开发者

ASP.NET MVC area namespace problem

开发者 https://www.devze.com 2023-03-22 00:13 出处:网络
I create a new area in my asp.net mvc 3 solution named admin. Visual studio automatically assign the names s开发者_如何学Cpace:

I create a new area in my asp.net mvc 3 solution named admin. Visual studio automatically assign the names s开发者_如何学Cpace:

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


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
    );
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号