1

Environment: Sitecore 9.0.2 + Glass mapper

I have a model class like this:

public class SingleStack
    {
        public Glass.Mapper.Sc.Fields.Image Logo { get; set; }

        public string Attraction_Name { get; set; }
        public string Destination_Name { get; set; }
        public bool Is_Atttraction { get; set; }

        [SitecoreId]
        public Guid ID { get; set; }

       public Glass.Mapper.Sc.Fields.Link Explore_More_Link { get; set; }


    }

From a list of object of class SingleStack, I am displaying the fields. On my website, everything is fine.

The situation changes in the Experience Editor.

The fields Attraction_Name and Destination_Name are not getting rendered. Logo and Explore_More_Link are getting rendered and editable.

Few points to note: 1. All the fields are coming from the same item in Sitecore.

  1. The ID field contains the GUID of the item being rendered.

Code to render in cshtml:

     @if (!string.IsNullOrEmpty(stack.Destination_Name))
{
@Html.Glass().Editable(stack, x => x.Destination_Name)
    }

There are no errors in console and log.

1 Answer 1

2

Based on your last question and this question I am adding some details-

In Glass mapper, two types of Models are being in use called - Template Models and Rendering Models - See more here - http://glass.lu/Blog/TemplateVsRendering

It seems you are using Rendering Models, these are models that are designed to contain just the properties required by a rendering. Rendering Models have some limitations, one of them is that it is difficult to link properties to the fields in Sitecore because the field name or display name in Sitecore name may differ and may contains space in it.

I will suggest you, to create a list of field name constants and then use attribute or fluent configuration to link these names to the properties on your view models -

[SitecoreField("Your Field Name")]
public string Destination_Name { get; set; }

or

public class SingleStack
    {
        [SitecoreField(Templates._SingleStack.Fields.Logo)]
    public Glass.Mapper.Sc.Fields.Image Logo { get; set; }

    [SitecoreField(Templates._SingleStack.Fields.AttractionName)]
    public string Attraction_Name { get; set; }

     [SitecoreField(Templates._SingleStack.Fields.DestinationName)]
    public string Destination_Name { get; set; }

    [SitecoreField(Templates._SingleStack.Fields.IsAtttraction)]
    public bool Is_Atttraction { get; set; }

    [SitecoreId]
    public Guid ID { get; set; }

   [SitecoreField(Templates._SingleStack.Fields.Explore_More_Link)]
   public Glass.Mapper.Sc.Fields.Link ExploreMoreLink { get; set; }    

    }

Where SitecoreField(Templates._SingleStack.Fields will have all your field names, make sure your field name is correct.

1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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