可在ASP.NET MVC我窝的地方? [英] Can I nest areas in ASP.NET MVC?

查看:181
本文介绍了可在ASP.NET MVC我窝的地方?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的MVC应用程序的跟踪网址:

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)

推荐答案

要完成上述所需的网址,只需指定它在你的管理区域的路由配置是这样的:

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.

这篇关于可在ASP.NET MVC我窝的地方?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆