Reputation: 13
When I use Glass Mapper's SitecoreContext().GetItem<Sitecore.Data.Items.Item>(ItemPath)
it works fine, but as soon as I use it with my custom model generated by TDS + Glass it returns null
.
My code is as follows:
NavigationHelper.cs
public class NavigationHelper
{
public static int GetChildCount()
{
var context = new SitecoreContext();
string g = "/sitecore/content/home/Site Settings/Top Navigation Items";
var t = context.GetItem<Models.sitecore.templates.Navigation.Navigation_Item_Folder>(g);
var v = context.GetItem<Items.Item>(g);
// t is always null, but v always finds the item correctly.
return t.Children.Count();
}
}
Models.sitecore.templates.Navigation.Navigation_Item_Folder
is a model generated by Glass and TDS and as follows:
/// <summary>
/// Navigation_Item_Folder
/// <para></para>
/// <para>Path: /sitecore/templates/Navigation/Navigation Item Folder</para>
/// <para>ID: c0f00c6b-145e-47f2-9427-57df58a612f1</para>
/// </summary>
[SitecoreType(TemplateId=INavigation_Item_FolderConstants.TemplateIdString)] //, Cachable = true
public partial class Navigation_Item_Folder : GlassBase, INavigation_Item_Folder
{
}
It's just a folder, so it has no fields on it. I've tried extending this partial class to include a title field, but that didn't fix the issue.
I have already tried the steps here: Sitecore Glass mapper GetItem<TypeName>(guid) always return null but they haven't helped.
Upvotes: 1
Views: 2821
Reputation: 714
Could you try the guid as {C0F00C6B-145E-47F2-9427-57DF58A612F1}
? I've seen standard Sitecore queries have case sensitivity issues when locating an item by template id.
Upvotes: 2