1

I have an ASP.NET MVC3 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. What I want to do it create some partial pages in the different areas and in the main application create a page that will render the partial pages.

Arthi Viji
  • 13
  • 2
  • For reference, in MVC3 you also can list all the areas using a similar approach as the one stated in [this answer](http://stackoverflow.com/a/15691878/1216184), using distinct you will avoid all duplicate values – Ferran Salguero Nov 16 '15 at 11:57

1 Answers1

1

Is there a way I can find out programmatically the number of areas that are present and their names

No AFAIK currently there isn't an easy and reliable way to do this. In ASP.NET MVC 4.0 though there will be, I promise :-)

Currently you might need to use reflection and look at all namespaces containing Areas.something and count them. Not very reliable.

Darin Dimitrov
  • 1,023,142
  • 271
  • 3,287
  • 2,928
  • I was thinking of doing that but wanted to know if there was a better way. – Arthi Viji Jul 06 '11 at 21:51
  • @Arthi Viji, the way areas are currently implemented, the framework doesn't really know about them. They are just special routes. This is one of the fields in which the team will improve in the future version and make areas first class citizens. – Darin Dimitrov Jul 06 '11 at 21:52
  • @DarinDimitrov - do you know if this has been added in MVC 4? – Matt Millican Jul 22 '13 at 20:14
  • @mmillican, yes it has been added. – Darin Dimitrov Jul 22 '13 at 20:19
  • @DarinDimitrov Any idea how to get a list of areas in an application? I've done a bit of searching / trial-error, but no luck so far. – Matt Millican Jul 22 '13 at 20:43
  • @DarinD, can you give an example in MVC4 for this then? I've found this one [**ASP.NET MVC4 List of all areas**](http://stackoverflow.com/questions/15690834/asp-net-mvc4-list-of-all-areas), but it isn't what you said about the first class thing. – cateyes Nov 10 '13 at 22:53