各个领域的ASP.NET MVC4名单 [英] ASP.NET MVC4 List of all areas

查看:265
本文介绍了各个领域的ASP.NET MVC4名单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我创建多个区域的ASP.NET应用程序MVC4,是有办法,我可以找出是present地区,他们的名字以编程的数量。

I have an ASP.NET MVC4 application in which I am creating multiple areas, is there a way I can find out programmatically the number of areas that are present and their names.

推荐答案

AreaRegistration.RegisterAllAreas(); 注册与每个区域路线 DataTokens [区] 其中值是区域的名称

The AreaRegistration.RegisterAllAreas(); registers each area route with the DataTokens["area"] where the value is the name of the area.

所以,你可以从已注册的区域名称 RouteTable

So you can get the registered area names from the RouteTable

var areaNames = RouteTable.Routes.OfType<Route>()
    .Where(d => d.DataTokens != null && d.DataTokens.ContainsKey("area"))
    .Select(r => r.DataTokens["area"]).ToArray();

如果您正在寻找的 AreaRegistration 本身,你可以使用反射来获得从 AreaRegistration 派生的类型的assambly。

If you are looking for the AreaRegistration themselves you can use reflection to get types which derives from AreaRegistration in your assambly.

这篇关于各个领域的ASP.NET MVC4名单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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