开发者

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.


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


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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜