I'm trying to access Sitecore 10.2
model fields using Glass.Mapper.Sc.92 version 5.8
, and registered all Glass.Mapper
services in GlassMapperConfigurator class. However facing the "Context is null" issue.
Created another class to register the controller
public class GlassCustomConfigurator: IServicesConfigurator
{
public void Configure(IServiceCollection serviceCollection)
{
serviceCollection.AddTransient<FooterController>();
}
}
Controller code:
public class FooterController : Controller
{
private readonly IMvcContext _mvcContext;
public FooterController(IMvcContext mvcContext)
{
_mvcContext = mvcContext;
}
public ActionResult Footer()
{
var model = _mvcContext.GetContextItem<FooterModel>();
return View(model);
}
}
GlassCustom.config to register the services
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
<sitecore>
<services>
<configurator type="Test.GlassCustomConfigurator, Test" />
<configurator type="Test.GlassMapperConfigurator, Test" />
</services>
</sitecore>
</configuration>
Any idea how can I fix this issue?