This is a migrated thread and some comments may be shown as answers.

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

1 Answer 51 Views
This is a migrated thread and some comments may be shown as answers.
Top achievements
Rank 1
David asked on 08 Dec 2012, 01:36 AM
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

1 Answer, 1 is accepted

Sort by
Petur Subev
Telerik team
answered on 12 Dec 2012, 08:45 AM
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!
Asked by
Top achievements
Rank 1
Answers by
Petur Subev
Telerik team
Share this question