Question with EpiServer Property list

Vote:
 

I had a property list with Name and Value. I made a selection factory to display the names to select one item from the property list. Following that I could get the value of the selected item in the UI. Sample code below.. 

public IEnumerable<ISelectItem> GetSelections(ExtendedMetadata metadata)
{
if (!_contentLoader.TryGet<HomePage>(ContentReference.StartPage, out var HomePage))
{
return Enumerable.Empty<ISelectItem>();
}
return HomePage.BannerAlertBackgroundColors?.Select(x => new SelectItem {Text = x.ColorName, Value = x.ColorHexValue });
}

This is how I used it in the block:

[SelectOne(SelectionFactoryType = typeof(BannerAlertColorSelectionFactory))]
public virtual string BannerBackgroundColor { get; set; }

I need to expand the property list to add one more item, Ex: Name, Value, Image. But I have to keep the implementation still same. User will be selecting the Name in the CMS. I need to update the selection factory some how to return the entire item so I can access Value and Image both in UI.

Any help is most appreciated.

#211449
Jan 08, 2020 20:29
Vote:
 

Do you need to see the image in edit mode? If not, do something like this?

return HomePage.BannerAlertBackgroundColors?.Select(x => new SelectItem {Text = x.ColorName + ", " + x.Image.Name, Value = x.ColorHexValue + ":" + x.Image.ContentLink.ID });
#214628
Jan 09, 2020 10:05
Dileep D - Jan 11, 2020 19:00
Thanks Tomas,
This is my planned alternative to fetch details but wanted to see if there's a way I could return the entire object itself to access the properties in the View instead of splitting the value and then read them.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.