question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

View rendering with unpublished datasource item resulting in error

See original GitHub issue

I’m using interfaces as my viewmodels for a hybrid WebForms and MVC Sitecore project. All my view renderings have their “Model” field left empty with views having @inherits GlassView<IModel> in them to dynamically bind data to them. This approach works fine except for an edge case scenario where the datasource item defined for the view rendering is not published resulting in this “The model item passed into the dictionary is of type ‘Sitecore.Mvc.Presentation.RenderingModel’, but this dictionary requires a model item of type IModel” error.

This error happens because both GetModel and GetModelFromView result in null passing the control back to Sitecore which then passes an item of type RenderingModel to the view.

To get around this - I tried setting “Model” field on the view rendering to the type of the model (e.g. NameSpace.IModel, Website - but that results in “Constructor on type Namespace.IModel not found” error.

Can someone please advise if 1) I’m doing something wrong here 2) there is any way to get around this problem?

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:16 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
fluxdigitalcommented, Aug 11, 2016

@mikeedwards83 I did something like this in the end to handle errors and invalid datasources: http://www.hhogdev.com/blog/2015/june/mvc-rendering-exception-handler.aspx

0reactions
andreicvasniuccommented, Feb 2, 2018

Hello, It seems I have the same bug or a similar one:

Inner Exception: The model item passed into the dictionary is of type ‘Sitecore.Mvc.Presentation.RenderingModel’, but this dictionary requires a model item of type ‘Feature.Model’.

I am using Sitecore 8.2.170728 and GlassMapper 4.4.0.199. When a Datasource for View rendering is empty, Sitecore returns the Context.Item (page item) instead. I would like to get just null in normal and edit modes. So I have decided to override the Process method in GetModelFromView and to create an instance of NullModel and to assign to model for my case. I also added a new DeleteNulModel processor to the end of getModel pipeline in order to find my case and to assign null to the model. After doing some debugging until the line of code when a render renders it in ExecuteRenderer, the model is still null. But when I let it go to render it I get the error above. I don’t get when Sitecore re-assigns it. The last getModel processor set it to null for sure.

Can anyone help me please to figure out what is going on?

Thanks Andrei

Read more comments on GitHub >

github_iconTop Results From Across the Web

Sitecore 8 throwing null exception when Datasource item ...
I have a rendering and its datasource is pointing to an item in the tree. · I publish the rendering but I don't...
Read more >
MVC rendering not being rendered in normal mode
If you see the rendering in your item on the web database and it all looks good but still don't see it being...
Read more >
Protect Your Sitecore Renderings From Missing Datasources
I tried to do what is stated in the title. If a content item to a rendering which references this in its data...
Read more >
Sitecore Experience Editor Tips! – Part 1 - RMC Digital
We are going to add the Rendering on a Sample Page, noticed that the Data Source is empty. Then if we open the...
Read more >
Null Explosion Prevention with Datasources!
Override renderer to null when there is an unpublished item refererenced by underlying view. return viewRenderer.Rendering.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found