1

I'm using interfaces for my Glass Mapper mappings, and I have a scenario where a view rendering I'm creating has a null datasource (due to the item being marked as never publish). I'm getting the message "the model item passed into the dictionary is of type 'Sitecore.Mvc.Presentation.RenderingModel' but this dictionary requires..." as a YSOD. Normally I'd create a model entry in Sitecore and hook it to the rendering, which usually covers this, but when I did it using an interface I got a message saying a constructor was required, which you can't create in an interface.

I have code in the rendering to check if it has a datasource, but it never gets there and errors out immediately. Is there any way to do what I'm trying to do with interfaces for models, or do I either a) need a concrete class, or b) need to use a controller rendering? The main reason for the interface models is there are a number of inheritances that I'm trying to set up, where a template might be inheriting from six others, and I didn't want to "junk up" the model with all of the repeated properties, if that makes sense. I'm trying to figure out the best practice here.

1

Please see this class:

https://github.com/mikeedwards83/Glass.Mapper/blob/master/Source/Glass.Mapper.Sc.Mvc/Pipelines/Response/GetRenderer/GetViewRenderWithItemValidation.cs

and this blog post:

http://sitecorepromenade.blogspot.co.uk/2015/05/passing-invalid-id-in-rendering.html

We're looking for long answers that provide some explanation and context. Don't just give a one-line answer; explain why your answer is right, ideally with citations. Answers that don't include explanations may be removed.

  • Very similar except for right near the end...is this something that's being considered for the main Glass project, curiously? Thanks! – Ken McAndrew Apr 19 '17 at 16:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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