开发者

Can I nest areas in ASP.NET MVC?

开发者 https://www.devze.com 2023-01-15 13:21 出处:网络
I want the follow URLs in my MVC application: /Admin/Acco开发者_Go百科unts/Groups /Admin/Accounts/Users

I want the follow URLs in my MVC application:

/Admin/Acco开发者_Go百科unts/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)


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.

0

精彩评论

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