Views: 12K
Replies: 1
Archived
|
MVC 3 strongly typed View in which ViewModel is a listI 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? @model Site.Areas.Account.Models.PhotosModel
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. public class PhotosModel : List<Photos> { } Sunil Patel, Jul 19, 2011
|
|
Reply 1You 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.
public class PhotosModel { public List<Photo> PhotoList { get; set; } public Photo Photo { get; set; } } I hope this helps. King Wilder, Jul 24, 2011
|