2015-09-07 27 views
0

我試圖讓Sitecore的8項目,MVC會存在,我收到以下錯誤:玻璃映射MVC:「RenderLink」這個名字不會在目前情況下

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

我有作爲引用(來自的NuGet包)

  • Castle.Core
  • Glass.Mapper
  • Glass.Mapper.Sc
  • ģ lass.Mapper.Sc.Mvc

我已經嘗試了一些與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的緩存。我不確定我錯過了什麼。 這裏是觀看/呈現的削減版本:

@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突出顯示它爲錯誤。 我只是看不到我錯過了什麼。任何幫助表示讚賞。

回答

3

改變這種

@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) 

額外的好處:你不應該設置佈局爲null。確保你沒有可能會導致這種情況的_ViewStart.cshtml。

+0

這就是機票!非常感謝你。它甚至在[Tutorial 12](http://www.glass.lu/Mapper/Sc/Tutorials/Tutorial12)裏回頭看,但我沒有意識到! 謝謝你的時間。 – Scarophion

相關問題