2016-03-21 12 views
0

コントローラレンダリングを使用して、私はFooter.csという1つのモデルを作成しました。glassmapperの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); 
} 

しかし、常にnull結果を得て、私のいずれかを助けてください。

+0

は、任意の数の理由だろう。あなたのサイトコアの設定方法の詳細を表示する必要があります。 – 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 =新しいSitecoreContext(); varモデル= ctx.GetItem

(ItemReferences.COPYRIGHT_TEXT); 戻るビュー(モデル); } –

+2

回答があれば、正しい答えを記入してください –

関連する問題