2016-03-21 41 views
0

我使用控制器渲染,我創建了一個名爲Footer.cs的模型,它具有以下屬性。無法自動映射在sitecore MVC(Razoe VIew)幫助玻璃映射器

[SitecoreType(TemplateId = "{1044CFB5-2B85-4A8D-9DCC-34764D2AF5B3}", AutoMap = true)] 
public class Footer 
{ 
    public virtual Item Item { get; set; } 
    [SitecoreField(FieldName ="Copyright Text First",FieldType = SitecoreFieldType.SingleLineText)] 
    public virtual string CopyrightTextFirst { get; set; } 

    [SitecoreField(FieldName ="Copyright Text Last",FieldType = SitecoreFieldType.SingleLineText)] 
    public virtual string CopyrightTextLast { get; set; } 
} 

在我的控制器:

public ActionResult FooterTemplate() 
{ 
    ISitecoreContext ctx = new SitecoreContext(); 
    var model = ctx.GetCurrentItem<Footer>(); 
    return View(model); 
} 

但是,總是得到空的結果,請大家幫幫我的任何一個。

+0

可以是任何數量的原因。您需要顯示您的sitecore配置方式的詳細信息。 – Liam

+2

頁腳項目是您當前的「頁面」項目還是數據源項目? –

+0

這是數據源項目 –

回答

0

您可以使用:

public ActionResult FooterTemplate() 
    { 
    ISitecoreContext ctx = new SitecoreContext(); 
    var model = ctx.GetCurrentItem<Footer>(RenderingContext.Current.Rendering.DataSource); 
    return View(model); 
    } 
+0

謝謝,我更新了我的代碼,現在它正在工作。 –

+0

public ActionResult FooterTemplate() { ISitecoreContext ctx = new SitecoreContext(); var model = ctx.GetItem

(ItemReferences.COPYRIGHT_TEXT); return查看(model); } –

+2

如果他回答幫助您標記答案正確 –

相關問題