【问题标题】:Error in controller rendering while using glass mapper使用玻璃映射器时控制器渲染出错
【发布时间】:2015-11-24 11:24:40
【问题描述】:

我已经在 sitecore 8.1 MVC 中实现了控制器渲染。我在 Index 方法中收到以下错误:

错误:给定的键不在字典中

代码:

{
var context = new SitecoreContext();
var Model = context.GetCurrentItem<BasePage>(); //Error comes here
return View(Model);

我错过了任何玻璃映射器文件吗?有什么建议吗?

【问题讨论】:

    标签: sitecore glass-mapper sitecore-mvc sitecore8.1


    【解决方案1】:

    当 Glass 无法找到该站点的上下文时,我通常会看到此错误。通常是因为站点定义配置中的错误。如果错误没有立即明显,请提供更完整的堆栈跟踪和您的站点定义配置。

    作为旁注。通常最好从GlassController 继承并使用其SitecoreContext 属性,或者使用SitecoreContext.GetFromHttpContext() 将ISitecoreContext 的实例注入到您的构造函数中。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-06-03
      • 1970-01-01
      • 2012-09-30
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多