Dofs
Dofs

Reputation: 19317

Passing correct model to partial view

I have been looking at this error for quite some time, and can't seem to figure out what I might have done wrong.

I have a partial view which is added like this:

        <% Html.RenderPartial("~/Views/ForumPosts/ForumPostCreateForm.ascx", ViewData.Model); %>

And the top of the partial view looks like this:

<%@ Control Language="C#" AutoEventWireup="true" Inherits="System.Web.Mvc.ViewUserControl<xxxx.Web.Controllers.ForumThreadsController.ForumThreadFormViewModel>" %>

The error I receive is the following:

The model item passed into the dictionary is of type 'xxx.Core.ForumThread', but this dictionary requires a model item of type 'xxx.Web.Controllers.ForumThreadsController+ForumThreadFormViewModel'.

If am not mistaken both takes the model called ForumThread, but apparently I must have missed something.

Upvotes: 1

Views: 940

Answers (3)

Ashwini Jindal
Ashwini Jindal

Reputation: 831

You must need to insure about what you are going to pass model into your partial view , try to pass a new object of model into partial view

Upvotes: 4

StriplingWarrior
StriplingWarrior

Reputation: 156748

If am not mistaken both takes the model called ForumThread...

According to the code you posted, the partial view takes a xxxx.Web.Controllers.ForumThreadsController.ForumThreadFormViewModel. Either change the top of your partial view, or find some way to pass a ForumThreadFormViewModel along on a ForumThread object.

Another solution would be to use RenderAction to allow an action to generate the ForumThreadFormViewModel you want.

Upvotes: 3

Andrey Tagaew
Andrey Tagaew

Reputation: 1603

Please, make sure that your Model is of type xxxx.Web.Controllers.ForumThreadsController.ForumThreadFormViewModel

To check this, look at the point in your controller where its returning the View. The object that you are putting into the method should be of type ForumThreadFormViewModel

Upvotes: 1

Related Questions