I have got a masterpage which uses a model @model.topics, I created a partial view which uses a model @model.ContactUsModel, And i am rendering that view in my master page , but it comes up with the error:
The model item passed into the dictionary is of type ‘Nop.Web.Models.Common.topics’, but this dictionary requires a model item of type ‘Nop.Web.Models.ContactUsModel’.
I am calling the partial view using :
@Html.Partial("Contact")
Any suggestions or advice what i am doing wrong here
Try using
The action has to return a
PartialViewfor this to work. You can then render it with the right model@Html.Partial()renders the partial view.It doesn’t invoke the action in the controller.
You can still give a model with this method like this:
@Html.Partial("Contact",someObject)If you don’t give a model with it, the page model will be given by default
and that is what happend with your code
@Html.Action()invokes the action in the controller.And then it is up to the action to give a result of any kind.
I hope this helps