0

Am using controller rendering, I created one model called Footer.cs and it has below properties.

[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; }
}

In My Controller:

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

But, always getting null result, please help me any one.

Liam
  • 27,717
  • 28
  • 128
  • 190
Suresh R
  • 229
  • 2
  • 11

1 Answers1

0

You can use:

  public ActionResult FooterTemplate()
  {
    ISitecoreContext ctx = new SitecoreContext();
    var model = ctx.GetCurrentItem<Footer>(RenderingContext.Current.Rendering.DataSource);
    return View(model);
  }
Vlad Iobagiu
  • 4,118
  • 3
  • 13
  • 22
  • public ActionResult FooterTemplate() { ISitecoreContext ctx = new SitecoreContext(); var model = ctx.GetItem
    (ItemReferences.COPYRIGHT_TEXT); return View(model); }
    – Suresh R Mar 21 '16 at 15:26