0

I'm using glass mapper and my template has a droplink list in it. When i attempt to retreive the item, it's bringing back the selected guid in the droplink instead of the name. How do I go about showing the name selected in the droplink versus the guid?

Dheeraj Palagiri
  • 1,829
  • 3
  • 23
  • 46

2 Answers2

6

If you'd like the name of the item instead of the GUID, why not use a Droplist? Or do you need the GUID for other purposes? Glass is simply returning what Sitecore is actually storing in this case (which for a Droplink would be the item GUID).

Otherwise, you should create a new class for the linked item which includes the item name, and then change your mapped property to return that class instead of a string.

FYI, though a Droplist might be the easier fix, use of that field type is not a good practice. Since the item name is stored instead of the GUID, changes to that item name do not cascade to linking items.

nickwesselman
  • 6,845
  • 2
  • 27
  • 46
3

I am giving a working example for techphoria414's answer for future use.

Imagine your droplink field contains the items of KeyValuePair type:

[SitecoreType(TemplateId = "Id")]
public partial interface IKeyValuePair
{
    [SitecoreField(FieldId = "Id")]
    string Key { get; set; }

    [SitecoreField(FieldId = "Id")]
    string Value { get; set; }

}

If your droplink field is SelectColourBar which is from template ColourBar

[SitecoreType(TemplateId = "Id")]
public partial interface IColourBar
{
    [SitecoreField(FieldId = "Id")]
    IKeyValuePair SelectColourBar { get; set; }
}

This will map SelectColourBar to KeyValuePair model, then one can access key or value.

Dheeraj Palagiri
  • 1,829
  • 3
  • 23
  • 46