1

The model item passed into the dictionary is of type 'Sitecore.Mvc.Presentation.RenderingModel', but this dictionary requires a model item of type 'xxx.models.Sitecore.IPage'.

I get above error if I statically load this like:

@Html.Sitecore().ViewRendering("~/Views/xxx/Generic/PageIntro.cshtml")

If I create a "View Rendering" item in Sitecore and load it from Presentation Details dynamically it works okay.

View I am trying to load "PageIntro" is a GlassView

Why is this?

3
  • Can you please provide more details on how the solution is set up. There are couple of questions like how is the Model generated (is it auto generated through the Glass Mapper), how are the controllers setup and any route config updates. Commented Jul 13, 2017 at 12:16
  • 1
    You can change your code and use @Html.Partial("~/Views/xxx/Generic/PageIntro.cshtml", Model) assuming that Model is the same what is defined in the containing page.
    – jammykam
    Commented Jul 13, 2017 at 17:30
  • 1
    @Jammykam That also works as well :-) Commented Jul 13, 2017 at 18:50

1 Answer 1

2

A View Rendering must always declare a Model of type RenderingModel which is the default used by Sitecore and that's the only type that will be returned if you use @Html.Sitecore().ViewRendering("").

My guess is that your View ~/Views/xxx/Generic/PageIntro.cshtml defines a Glass Model as the model type being returned.

Instead you should be using a Controller Rendering. To do that, I would recommend that you use `@Html.Sitecore().Rendering("{Guid of Defined Controller Rendering In Sitecore}")

Then define in your controller rendering definition in Sitecore a Controller and Action that will be used to build that custom model used by your view.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.