I have a partial view: UnderAge.cshtml
I'm getting a list of Artist
(a model class) in that partial view. I have an Index
parent view, which displays a list of Person
(other model class), where I want to add the content from the Partial View UnderAge.cshtml
. I've checked that the partial view works good and it has a list of two elements, the problem is when I try to show the list of Artist
from partial view UnderAge.cshtml
on Index
parent view, maybe because Index is using elements from other model class (Person).
Partial View(I'm putting just the @model
part), it display a list of Artist model class:
@model IEnumerable<AlexMusicStore.Models.Artist>
Parent view(has a different @model
) And I'm getting this exception:
The model item passed into the dictionary is of type 'System.Collections.Generic.List'1[AlexMusicStore.Models.Person]', but this dictionary requires a model item of type 'System.Collections.Generic.IEnumerable'1[AlexMusicStore.Models.Artist]'.
@model IEnumerable<AlexMusicStore.Models.Person>
<div>
@{
Html.RenderPartial("~/Views/Artists/UnderAge.cshtml", Model);
}
</div>
Model
(which is a collection ofPerson
to a view which expects a collection ofArtist
– user3559349Html.RenderPartial("~/Views/Artists/UnderAge.cshtml", Model.Artist);
So assuming your Model has a property calledArtist
and it is of typeIEnumerable<AlexMusicStore.Models.Artist>
– Rajshekar ReddyIEnumerable<Person>
- it cant possibly have a property which isArtist
:) – user3559349