-
Notifications
You must be signed in to change notification settings - Fork 121
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
View rendering with unpublished datasource item resulting in error #163
Comments
Update: I can get around the issue by replacing |
After debugging through the code - I think the issue lies in this method:
Basically |
For me I think the SC logic is incorrect. Within the GetModel pipeline you have the processor: Sitecore.Mvc.Pipelines.Response.GetModel.CreateDefaultRenderingModel, Sitecore.Mvc Which forces the standard RenderingModel without any checks. This to me is incorrect, if the item / datasource is null then the model should be null. I would try removing this entry to see if that solves your problem. I will get some opinions of other community members |
I think the idea of Sitecore is here similar to I don't think this is something Glass should handle. If I needed to solve this issue I would probably override the |
Thank you for your feedback guys - I will try these options out. From what I've tried so far - just removing
@aquasonic - can you please advise what's the best way to check "if the desired model is a Glass model"? |
Update: as expected it failed at a few places along the pipeline. These are the places where I ended up patching the Sitecore pipelines.
|
@hiraldesai you could create a base class/interface |
I have just tried this on an SC8 instance and don't get the problem. Which SC version are you using? |
Ok this only relates to scenarios where the Model is derived from the CSHTML file using GetModelFromView |
@aquasonic - Thanks. @mikeedwards83 - I'm using 7.2. Instead of trying to patch at a few places like above, I was trying to find one place to patch this (or patch in as few places as possible). I went down the path of creating a custom model locator and a few other things but in the end it just turned out to be as simple as this:
Initial tests show that it's not breaking anything - I will keep testing and share this with Sitecore team too later. Edit: Made a slight adjustment to stop page editor from throwing error as per #144 |
Hi Do you mind if I add this to the Glass.Mapper site as a blog post/documentation but giving you the credit? Mike |
No problems Mike! On Mon, 24 Aug 2015 at 4:45 pm Mike Edwards notifications@github.com
|
@mikeedwards83 This is great, it fixed problems with our content editors removing components and leaving broken links to data sources. However Ideally what I would like to do is render out a message in place of the component when in editing mode to say something like 'incorrect data source configured, please edit'. I looked at doing this by extending glassview, e.g: http://www.chrissulham.com/protect-your-sitecore-renderings-from-bad-datasources/. However it seems if the rendering is returned as null then It will never hit my baseglassview as it isn't even trying to render the component anymore. Any ideas how to do this in GetViewRendererWithItemValidation instead? |
@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 |
@mikeedwards83 I am having the same issue because my DataSource isn't published when using a ViewRendering. I tried using z.Glass.Mapper.Sc.ViewRender.config, but now I get a NullReferenceException.
At the top of the file it tells me to "update the code in the GlassMapperScCustom", though I have no idea what to add/update inside this class. |
Hello, 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 |
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 typeIModel
" error.This error happens because both
GetModel
andGetModelFromView
result in null passing the control back to Sitecore which then passes an item of typeRenderingModel
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 typeNamespace.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?
The text was updated successfully, but these errors were encountered: