ListView Models vs the model used by the View hosting the ListView

2 posts, 0 answers
  1. David
    David avatar
    4 posts
    Member since:
    Jun 2012

    Posted 07 Dec 2012 Link to this post

    I have an MVC4 view that hosts a ListView. The ViewModel contains the properties required by the ListView as well as properties used by the main view. Problem is the ListView uses an IEnumerable of the ViewModel and my main view doesn't. Seems I can't have both in 1 view (or can I?).

    For example
    The MVC view that loads in the listview as a partial view binds to the following model:

    @model app.WebSiteModels.EditPhotoViewModel

    where EditPhotoViewModel is defined as :

    public class EditPhotoViewModel
            public WebsitePhoto WebsitePhoto { get; set; }  //WebsitePhoto is used in my main view
            public IEnumerable<Photo> PhotoList { get; set; }  //the Photo properties are used in my listview

    The listview binds to an IEnumerable version of EditPhotoViewModel:
    @model IEnumerable<app.WebSiteModels.EditPhotoViewModel>


    @model app.WebSiteModels.EditPhotoViewModel doesn't work with the viewlist 
    @model IEnumerable<app.WebSiteModels.EditPhotoViewModel> doesn't work with my main view

    I must be missing something pretty basic here - please assist asap as I have been trying to figure this out for a few days now and this is urgent.

    many thanks
  2. Petur Subev
    Petur Subev avatar
    1882 posts

    Posted 12 Dec 2012 Link to this post

    Hello David,

    I am not sure I understand your case. Basically you can specify the type of the ListView through the generic overload of the ListView.

    @model EditPhotoViewModel

    Kind Regards,
    Petur Subev
    the Telerik team
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Back to Top