Glass Mapper MVC:当前上下文中不存在名称 'RenderLink'

Glass Mapper MVC: The name 'RenderLink' does not exist in the current context

我正在尝试使用 MVC 进行 Sitecore 8 项目,但出现以下错误:

Compiler Error Message: CS0103: The name 'RenderLink' does not exist in the current context

我有参考资料(来自 nuget 包)

我用 views/web.config 做了一些尝试。也许有冲突?

<namespaces>
        <add namespace="Sitecore.Mvc" />
        <add namespace="Sitecore.Data.Items" />
        <add namespace="System.Web.Mvc" />
        <add namespace="System.Web.Mvc.Ajax" />
        <add namespace="System.Web.Mvc.Html" />
        <add namespace="System.Web.Optimization"/>
        <add namespace="System.Web.Routing" />
        <add namespace="TDSExample.Web" />
        <add namespace="TDSExample.Entities.Ids" />
        <add namespace="Glass.Mapper.Sc" />
      </namespaces>

我已经清除了 Sitecore 缓存。我不确定我错过了什么。 这是 view/rendering:

的简化版本

@model Glass.Mapper.Sc.Web.Mvc.GlassView
<TDSExample.Entities.Templates.Header.Header>

  @using Glass.Mapper.Sc @{ Layout = null; var dataSource = Sitecore.Context.Database.GetItem(Sitecore.Mvc.Presentation.RenderingContext.Current.Rendering.DataSource) ?? Sitecore.Context.Item; }

  <h1>@Model.Editable(x => x.Title, dataSource)</h1>
  <p>
    @Model.Editable(x => x.Subtitle, dataSource)
  </p>
  @RenderLink(x => x.ReadMoreLink, dataSource, new { @class = "read-more" })

这是渲染图的缩减版:

@model Glass.Mapper.Sc.Web.Mvc.GlassView
    <TDSExample.Entities.Templates.Header.Header>

      @using Glass.Mapper.Sc @{ Layout = null; var dataSource = Sitecore.Context.Database.GetItem(Sitecore.Mvc.Presentation.RenderingContext.Current.Rendering.DataSource) ?? Sitecore.Context.Item; }

      <h1>@Model.Editable(x => x.Title, dataSource)</h1>
      <p>
        @Model.Editable(x => x.Subtitle, dataSource)
      </p>
      @RenderLink(x => x.ReadMoreLink, dataSource, new { @class = "read-more" })

测试场渲染得很好。我一定是在某处遗漏了一个参考。放置“@using Glass.Mapper.Sc”或“@using Glass.Mapper.Sc/Mvc”停止 VS 将其突出显示为错误。 我只是看不到我错过了什么。感谢任何帮助。

改变这个

@model Glass.Mapper.Sc.Web.Mvc.GlassView<TDSExample.Entities.Templates.Header.Header>

进入这个

@inherits Glass.Mapper.Sc.Web.Mvc.GlassView<TDSExample.Entities.Templates.Header.Header>

并在视图而不是模型上访问方法:

@Editable(m => m.Title)
@RenderLink(m => m.ReadMoreLink)

<!--this should work as well for links--> 
@Editable(m => m.ReadMoreLink)

额外的好处:您不必将布局设置为空。确保你没有 _ViewStart.cshtml 这可能会导致这种情况。