Is there a way I can get the names of the areas in an MVC project?
Here\'s a few ways I can think of:
a) If I had the source, I could browse through the proj
This thread was helpful in finding the answer, but nobody here posted it explicitly. Here is what I came up with, but do note you may need to adjust it depending on whether all of your areas are in the same assembly.
private IEnumerable GetAllAreasRegistered()
{
var assembly = this.GetType().Assembly;
var areaTypes = assembly.GetTypes().Where(t => t.IsSubclassOf(typeof(AreaRegistration)));
var areas = new List();
foreach (var type in areaTypes)
{
areas.Add((AreaRegistration)Activator.CreateInstance(type));
}
return areas;
}