Search code examples
model-view-controllersitecorecastle-windsorglass-mappersitecore8.1

Sitecore 8.1: Glass.Mapper & Razor


Running a new site on Sitecore 8.1 - installed and setup Glass.Mapper but I cannot use calls such as @RenderImage - it's complaining that i'm missing the reference to Glass.Mapper.Sc.Mvc, which I have already.

The following are the Nuget modules installed for Glass.Mapper:

  • BoC.Glass.Mapper
  • BoC.Glass.Mapper.Sc
  • BoC.Glass.Mapper.Sc.CastleWindsor
  • Castle Windsor
  • Castle.Core
  • Glass.Mapper.Sc

I have it installed on another instance of Sitecore (7.5) - an older version of Glass.Mapper, but I've noticed that the Nuget packages do not exist anymore.

Any ideas?

Thanks!

Dan


Solution

  • BoC.Glass.Mapper is a fork of Glass Mapper, and I believe it has not been updated to V4. Remove it (and any configs that it added or deployed) and start again I say. Just add the Glass.Mapper.Sc nuget package will add in the correct dependencies and is compatible with Sitecore 8.1.

    Just to be doubly sure, this is the correct version: https://www.nuget.org/packages/Glass.Mapper.Sc/

    Make sure you have Sitecore.Kernel and System.Web.Mvc referenced in your project since there is a post-install step in the nuget package that adds the correct versions of Glass dlls to your project.

    To make things simpler V4 uses a Powershell script to decided which references to add to your project, it checks both the Sitecore.Kernel version and the System.Web.Mvc version and then installs the appropriate Glass.Mapper.Sc and Glass.Mapper.Sc.Mvc assembly.

    With regards to @RenderImage, either inherit your view from GlassView<> or better to use the extension methods, e.g. @Html.Glass().RenderImage().

    More info here: http://glass.lu/Blog/GlassV4