0

We recently upgraded to 9.1 and updated our glassmapper to 5.4.1. After doing the upgrade and running our application I am getting this error. We dont have any model definition in siteocre and this is our layout page. i have spent the better part of my 2 days trying to figure out the reason. Any guidance on this would help.

    Server Error in '/' Application.
    The model item passed into the dictionary is of type 'Sitecore.Mvc.Presentation.RenderingModel', but this dictionary
 requires a model item of type MyProjectNameSpace.Model
   Description: An unhandled exception occurred. 
    
   Exception Details: System.InvalidOperationException: The model item passed into the dictionary is of type
 'Sitecore.Mvc.Presentation.RenderingModel', but this dictionary
 requires a model item of type MyProjectNameSpace.Model.

This is full error on the page. enter image description here

My Layout.Cshtml File has the following code : ( i tried both ways. line 3 / line 4)

enter image description here

Please ignore the error on my model name. i just changed it for the sake of screenshot. in reality it will have a proper namespace and model name.

Also this ishappening with new Glassmapper version. never had the issue with sitecore 8.1 and older version of GM.

  • 1
    This sounds like your rendering is now a View Rendering instead of a controller rendering. Can you look in Sitecore and see what template your rendering is current using? – Chris Auer May 26 '19 at 3:43
  • @chris it is a blank layout that I am trying to render. I just added the title for demo. There are currently no renderings added to that layout as of now. – Night Monger May 26 '19 at 5:37
  • I didn't think you could specify a custom model on a layout.. Even if you can though, I'm not sure why you would? Means your title needs to be on every single item that uses this layout. And even if it is architected that way (which is a bad practice IMO), you would lose out on many of the benefits of using a rendering, such as output caching and personalization. If you really do want something like this, I would advise at using a Static Controller Rendering instead. – Dylan Young May 27 '19 at 0:53
  • @DylanYoung Appreciate your response. the title is just an example. In reality, we use it for more generic stuff like passing the fav icon, configure meta tags etc that are at the head level. Also, even i take this out of the layout and add it to view rendering, the behaviour is same. would you know why this happens? – Night Monger May 27 '19 at 4:49
1

I think this issue may have been fixed in version 5.4.21 http://www.glass.lu/Mapper/Releases.

There was an error in how Glass was caching view types which has been resolved. Can you update and see if this solves your issue.

Commit: https://github.com/mikeedwards83/Glass.Mapper/commit/b4d5bb156110f990ac67f4e2a9a3274bbcf14137

| improve this answer | |
  • I know this is a bit old and it seems nightmonger never responded. I have this same issue and I am on 5.5.28 of glass for 9.1. I have looked at the code in dotPeek as well to make sure I have this change but it has not changed this behavior. The goal is to not have the page error out because a data source is not set up yet. Any ideas? – ToddB Aug 12 '19 at 20:52

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.