0

I have this model in my view:

@model MGDanismanlik.Controllers.SettingsController.WorkCampClas 

I call this partial view bottom of the view:

@Html.Partial("MonthlyResultPartial") 

This is the model I use in MonthlyResultPartial:

@model IEnumerable<MGDanismanlik.Controllers.SettingsController.WorkCampaignResultClass> 

But when I run it I got this error.

The model item passed into the dictionary is of type 'MGDanismanlik.Controllers.SettingsController+WorkCampClas', but this dictionary requires a model item of type 'System.Collections.Generic.IEnumerable`1[MGDanismanlik.Controllers.SettingsController+WorkCampaignResultClass]'.

What's the problem? I use different model in my partial view. How can I solve this?

7
  • 2
    Pass the model in as a parameter: @Html.Partial("MontlyResultPartial", model)
    – GH DevOps
    CommentedApr 25, 2023 at 16:33
  • Your Partial View is expecting an object of type IEnumerable<WorkCampaignResultClass> but your View is passing in an object of type WorkCampaignResultClass. You'll need to adjust either your View or Partial View so that the types align.CommentedApr 25, 2023 at 16:37
  • @bschellekens why my view and my partial view gotta have same models? Arent they seperated views?CommentedApr 25, 2023 at 16:43
  • Your view and partial view do NOT have to use the same model, BUT if you do NOT explicitly pass a reference to the model for the partial, then it is implied that the partial uses the same model. See the comment from @GHDevOps for the call signature that you want to use.CommentedApr 25, 2023 at 16:53
  • I tried it but the model returned null. I have this --> public PartialViewResult MonthlyResultPartial() {...} in my controller. I send model in this method to my partial view. I couldnt understand whats the problem.CommentedApr 25, 2023 at 17:02

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.