views:

54

answers:

3

Is there a way to get a list of all the Views defined in an ASP.NET MVC project? Is there a built-in enumeration anywhere or should I be looking toward reflection?

A: 

Reflection is your friend in this case. I don't think the enumeration exists already.

Kindness,

Dan

Daniel Elliott
+1  A: 

Programmatically accessible View Names is one of the many features offered by the T4MVC template. If it should not fit your needs exactly, you can still have a look and see how it's done there.

Adrian Grigore
A: 

something along these lines should get you started

for (methods in controller)    
    typeof(ActionResult).IsAssignableFrom(methodInfo.ReturnType)

that's pseudo, not sure if it's the proper properties and what not... the one thing you'll have to be careful of is only get methods on the declaringtype, not on the base types.

typeof(Controller).GetMethods(
    BindingFlags.Instance | 
    BindingFlags.DeclaredOnly | 
    BindingFlags.Public)

hope that's enough to be dangerous and get you started.

neouser99