Reputation: 1321
I've got a Model that contains search results for a grid as a child object. I would like to pass this child object of the Model to a partial view as a model, but am getting this error:
The model item passed into the dictionary is of type 'Refunds.Models.RefundModel', but this dictionary requires a model item of type 'Refunds.Models.CarSearchModel'.
public class RefundModel(){
public string SearchString{get; set;}
public List<SearchResult>{get; set;}
}
This Model goes to a view that contains a sub view. I attempt to send SearchResults list to this sub view when the error message comes up:
@Html.Partial("_CarSearch", Model.SearchResults)
Model.SearchResults is of type CarSearchModel, but the partial is thinking I am sending it the parent type (RefundModel). Can't you send a part of a Model to a partial view as that partial view's model?
Upvotes: 0
Views: 1291
Reputation: 6423
what you have provided is incomplete. You need to make sure that what you are passing to the partial matches the model defined at the top. so if you view model on the parent page has
public List<SearchResult> SearchResults { get; set; }
then you can pass the model to your partial as you have set up. The top of your partial should have
@model List<SearchResult>
Search result will need to be the full path to where that model is defined.
Upvotes: 2