Sitecore 8.1:Glass.Mapper & 剃刀

Sitecore 8.1: Glass.Mapper & Razor

运行 Sitecore 8.1 上的一个新站点 - 安装和设置 Glass.Mapper 但我无法使用 @RenderImage 之类的调用 - 它抱怨我缺少对 Glass.Mapper 的引用.Sc.Mvc,我已经有了。

以下是为 Glass.Mapper 安装的 Nuget 模块:

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

我将它安装在 Sitecore (7.5) 的另一个实例上 - Glass.Mapper 的旧版本,但我注意到 Nuget 包不再存在。

有什么想法吗?

谢谢!

BoC.Glass.Mapper 是 Glass Mapper 的一个分支,我相信它还没有更新到 V4。删除它(以及它添加或部署的任何配置)并重新开始我说。只需添加 Glass.Mapper.Sc nuget 包即可添加正确的依赖项并与 Sitecore 8.1 兼容。

再次确认一下,这是正确的版本:https://www.nuget.org/packages/Glass.Mapper.Sc/

确保您的项目中引用了 Sitecore.KernelSystem.Web.Mvc,因为 nuget 包中有一个 post-install 步骤,可以将正确版本的 Glass dll 添加到您的项目。

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.

关于 @RenderImage,要么从 GlassView<> 继承您的观点,要么更好地使用扩展方法,例如@Html.Glass().RenderImage().

更多信息在这里:http://glass.lu/Blog/GlassV4