Sitecore Glass Mapper always null

血红的双手。 提交于 2019-11-29 14:20:25

Did you check your Sites.config and the default language for this website? There could be a difference between the language which is defined in your Sitecore languages folder and your configuration.

I had a similar problem with one of my projects where I changed the Sitecore.Context.Language to "nl" instead of "nl-NL". The glass mapper will return null, but Sitecore.Context.Database.GetItem will return an object in this case.

Most of the times it is a language issue. The mapper returns a null object when you do not have versions in the current or given language.

What can be confusing is that Sitecore.Context.Database.GetItem returns an object, even if it does not have a version in the current language. Be sure to check that item.Versions has any.

Some things you may try (this didn't fit in the comments field)

1) Confirm that the related fields in the Sitecore Item object contain values (so Sitecore.Context.Item for your "c" var and Sitecore.Context.Database.GetItem("path") for your "d" var)

2) Try to encapsulate the GetItem/GetCurrentItem call in a VersionCountDisabler, like this:

T01_Homepage model = null;

using (new VersionCountDisabler())
{
  var context = new SitecoreContext();
  model = context.GetItem<T01_Homepage>("path");
}

// Do you have data in model now?

3) Try to encapsulate the same call with a SecurityDisabler. Just to confirm it's not a security issue.

4) If you still don't know what it is, please update your question with some (simplified) code for your model.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!