Can I nest areas in ASP.NET MVC?

 ̄綄美尐妖づ 提交于 2019-12-11 06:43:42

问题


I want the follow URLs in my MVC application:

/Admin/Accounts/Groups
/Admin/Accounts/Users

I know I could create an Area named Admin, and then create Groups and Users controllers inside that area.

Could I instead create nested areas? (An Area named Admin, and inside of this area an Area named Accounts)


回答1:


To accomplish your desired URL above, just specify it in the route configuration of your "Admin" area like this:

public override void RegisterArea(AreaRegistrationContext context)
{
    context.MapRoute(
        "Admin_default",
        "Admin/Accounts/{controller}/{action}/{id}",
        new { action = "Index", id = UrlParameter.Optional }
    );
}

No need to create Groups or Users controllers.



来源:https://stackoverflow.com/questions/3669136/can-i-nest-areas-in-asp-net-mvc

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