Programmatically get a list of MVC Views?

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 look at reflection?

+6
asp.net-mvc views view
source share
4 answers

Programmatically accessible name lookup is one of many features offered by the T4MVC template . If this does not meet your needs, you can still look and see how it is done.

+2
source share

Reflection is your friend in this case. I do not think the listing already exists.

Kindness,

Dan

0
source share

something in this direction should begin

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

what is pseudo, not sure if these are the right properties and what isn't ... the only thing you need to be careful about is to get methods of type declaringtype only, not base types.

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

I hope that this is enough to be dangerous and start working.

0
source share

Because ASP.NET MVC supports configuration convention, it is best to look at all the files in the ~ / Views directory - no reflection is required.

0
source share

All Articles