各个领域的ASP.NET MVC4名单 [英] ASP.NET MVC4 List of all areas
问题描述
我在我创建多个区域的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屋!