I'm trying to get items from Sitecore using GlassMapper 5 and after trying in many ways the properties in my object are always null.
Here are my templates.
And this is my content tree structure
The MainNav item is being used as datasource of a rendering and this how I'm getting it in the controller.
public ActionResult NavigationHeader()
{
var ds = MvcContext.GetDataSourceItem<MainNav>();
if (ds == null)
{
return null;
}
return View("~/Views/Redesign/Navigation/NavigationHeader.cshtml", ds);
}
I've tried to disable lazy loading
var ds = MvcContext.GetDataSourceItem<MainNav>(new GetKnownOptions { Lazy = Glass.Mapper.LazyLoading.Disabled })
But by doing that an exception is thrown Model depth check failed. Model graph too large, enable lazy loading.
Here is how my MainNav class is defined
[SitecoreType(TemplateId = "{93110014-14DC-4380-B031-54A31358AD9E}")]
public class MainNav : GlassMapperBase
{
[SitecoreField(FieldId = "{63A954E5-5A8F-46DE-B361-7C2CEB908F8A}")]
public Image Logo { get; set; }
[SitecoreChildren]
public IEnumerable<INavigation> Navigation { get; set; }
}
I've already tried to enable AutoMap and EnforceTemplate.
I've already checked the Template Id as well as the Field Id and they are correct.
I've already removed the SitecoreType annotation from MainNav class.
I've already checked the MainNav Item versions and there is only one.
I've already checked the web database and everything is exactly like in the master.
I've already checked the language and both, the site definition and the Sitecore.Context.Language are defined as "en".
In the view, when I try to access Model.Logo or Model.Navigation, those properties are always null but in the immediate window, I can access TemplateId or Name properties defined in GlassMapperBase class.
I really don't know what else to try.