1

I have a series of Infographic Items being added to a Infographic Container. The Infographic Container Model is as follows and works just fine:

namespace MyNamespace
{
    [SitecoreType(AutoMap = true)]
    public class InfographicContainerViewModel : BaseTemplateViewModel
    {
        public virtual string InfographicTitle { get; set; }

        public virtual string Description { get; set; }
    }
}

For my Infographic Item Model I've done essentially the same thing, but the fields are always mapping to null. Stepping through the debugger, I can see that the item itself is being mapped to correctly (Correct IDs, name, ect.) and the item is in the correct language. My first ideas were to add in the Template ID to the SitecoreType attribute and place the names of the fields in the SitecoreField attributes, but neither resulted in a correct mapping. Here is my Infographic Item Model as it stands now:

namespace MyNamespace    {
    [SitecoreType(TemplateId = "{5E6DF63A-0327-4587-8E72-AB35A7184200}", AutoMap = true)]
    public class InfographicItemViewModel : BaseTemplateViewModel
    {

        [SitecoreField("ItemTitle")]
        public virtual string ItemTitle { get; set; }

        [SitecoreField("ExpandedTitle")]
        public virtual string ExpandedTitle { get; set; }

        [SitecoreField("ExpandedDescription")]
        public virtual string ExpandedDescription { get; set; }
    }
}

Here is a screenshot of the debugger where you can see the fields mapping to null:

enter image description here

And here is a screenshot of the template as it exists in Sitecore:

enter image description here

enter image description here Does anyone know what could be going on here?

3
  • Just to make sure: is this template published with all subitems? UPD: and second typical case: do you have correct language version for the item? – Daniil Nov 23 '16 at 14:37
  • I've published a few times to see if that was the issue. Just ran another one and it had no effect. I've also triple checked the language versions and they are correct. Both the container and items have a version in English. – c-bro Nov 23 '16 at 14:40
  • Can you show how do you load your model? It might be an issue related to the Infer type attribute. (glass.lu/Mapper/Sc/Tutorials/Tutorial17) – Andrey Bobrov Nov 24 '16 at 3:07
3

I eventually found the source of the mapping problem. I was unaware that we were using a GlassMapper extension that automatically handles spaces in fields names. For example:

public virtual string ItemTitle { get; set; }

Would automatically try to map to the field Item Title.

By naming my fields without spaces in my template I inadvertently broke the logic in the GlassMapper extension so the fields were never able to resolve correctly. By changing the fields in my template to add spaces, I fixed the issue.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.