Try our conversational search powered by Generative AI!

Property List Image Help

Vote:
 

Hi,

I am trying to get an image field in a property list to show up as a thumbnail image rather than just the id of the image. I have found a post with an example of how to do this but i'm not sure if it works with the latest version of EPiServer. When i copied the c# code for the meta data attribute from this example: https://gregwiechec.com/2015/12/propertylist-with-images/ i get an error on the first line (var extendedMetadata = (ExtendedMetadata)metadata;) saying that i can't convert ModelMetadata to EPiServer.Shell.ObjectEditing.ExtendedMetadata.

public class TimelineImageMetadataAttribute : Attribute, IMetadataAware
    {
        public TimelineImageMetadataAttribute()
        {

        }

        public void OnMetadataCreated(ModelMetadata metadata)
        {

            var extendedMetadata = (ExtendedMetadata)metadata;

            var collection = ((ExtendingPropertyList.Models.Pages.ContactListProperty)metadata.Model).List
             .Where(cr => cr.Image != null)
             .Select(cr => new
             {
                 id = cr.Image.ID,
                 imageUrl = ServiceLocator.Current.GetInstance().Get(cr.Image).PreviewUrl()
             });
            extendedMetadata.EditorConfiguration.Add("mappedImages", collection);
        }
    }

Has anyone used this code to get images showing up as thumbnails like in the example? I'm not sure if any of this code wil work and i don't want to get stuck into the dojo code (i have not worked with dojo before) unless i know this is actually going to be possible.

can anyone point me to some up to date, working code for this? Or can anyone help me see what i am missing in my attribute?

Thanks

Sam

#198111
Edited, Oct 22, 2018 10:25
Vote:
 

There are different ModelMetadata classes in different namespaces.

Make sure that you're using System.Web.Mvc.ModelMetadata

using System.Web.Mvc;
#198115
Edited, Oct 22, 2018 12:27
* 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.