MVC 3 strongly typed View in which ViewModel is a list
I am using MVC 3 Razor and have a ViewModel that itself is a list of objects, say List<Photo>.
How do I declare this at the top of the view? I.e. what does PhotosModel look like?
By the way, I know I can nest the list within a ViewModel, but it is the only property, so I would rather not do that.
Sunil Patel, Jul 19, 2011
You should handle this differently. Having a view model is a best practice, but you should instead make a property that is of type List<Photo>. If you also have a property for a single Photo object, then you can use this view model for both lists, and details. And your page declaration can remain as you have shown.
I hope this helps.
King Wilder, Jul 24, 2011