The model element passed to the dictionary is of type

I have a mistake that I understand, but I can’t figure out how to solve it correctly.

I have a MasterPage, from this MasterPage I call:

<% Html.RenderPartial("Tags"); %>

Tags are a strongly typed representation that looks like this:

<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<IEnumerable<JegManglerEn.Controllers.CategoryCount>>" %>

I am returning a PartialView as follows:

return View("Tags", result);

where the result is correct and type:

List<CategoryCount>

Error:

The model element passed to the dictionary has the type "System.Collections.Generic.List 1[JegManglerEn.Item]', but this dictionary requires a model item of type 'System.Collections.Generic.IEnumerable1 [JegManglerEn.Controllers.CategoryCount]".

So the setup is this:

MasterPage loads the view, which takes the JegManglerEn.Item collection, and also tries to load the PartialView, which takes the JegManglerEn.Controllers.CategoryCount collection ... but does not.

, - RenderPartial, , RenderAction, .

, MVC soruce startup Reflector.

!

+3
2

Html.RenderPartial, . , , , .

RenderPartial - , , , , :

Html.RenderPartial("Tags", Model.Tags);

, RenderAction, , , (, , , ).

+5

ViewUserControl<IEnumerable<JegManglerEn.Controllers.CategoryCount>>

ViewUserControl<List<JegManglerEn.Controllers.CategoryCount>>
0

Source: https://habr.com/ru/post/1777213/


All Articles