Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • suzyb 474 posts 932 karma points
    Jul 15, 2015 @ 13:46
    suzyb
    0

    Issue with DittoMultipleMediaPickerConverter returning null

    I'm trying to get a list of images from a multi media picker using the DittoMultipleMediaPickerConverter but it seems to be returning null.

    This is my code

    [TypeConverter(typeof(DittoMultipleMediaPickerConverter))]
    [UmbracoProperty("solutionsNavigationImages", "solutionsNavigationImages", false, null)]
     public List<string> SolutionsNavigationImages { get; set; }
    

    The property solutionsNavigationImages has images selected yet the property is null when I try to access it in my view. As I understand it the above is correct so what else could be causing the property to be null.

  • Lee Kelleher 4020 posts 15802 karma points MVP 13x admin c-trib
    Jul 15, 2015 @ 14:40
    Lee Kelleher
    0

    Hi Suzy,

    What values are you expecting back for the property?

    The property-type is List<string>, what string values are you expecting to be in the list?

    Thanks,
    - Lee

  • suzyb 474 posts 932 karma points
    Jul 15, 2015 @ 14:45
    suzyb
    0

    Given the other mentions on the forum of the MultipleMediaPickerConverter I assumed it would give a list of the image URLs.

  • Lee Kelleher 4020 posts 15802 karma points MVP 13x admin c-trib
    Jul 15, 2015 @ 14:54
    Lee Kelleher
    100

    The issue here is that the DittoMultipleMediaPickerConverter will return a bunch of IPublishedContent (media) objects... but trying to convert that to a string will return null.

    The solution for this is to have a class/model that can represent the media item. See James South's reply on another post:

    https://our.umbraco.org/projects/developer-tools/ditto/ditto-feedback/65149-TypeConverter-not-being-fired#comment-220766

    public class YourModel
    {
        /* ... other properties ... */
    
        [TypeConverter(typeof(DittoMultipleMediaPickerConverter))]
        public List<Image> SolutionsNavigationImages { get; set; }
    }
    
    public Image
    {
        /* ... add properties (if you want) ... */
    
        public string Url { get; set; }
    }
    

    Cheers,
    - Lee

  • suzyb 474 posts 932 karma points
    Jul 15, 2015 @ 14:56
    suzyb
    0

    ah I see.

    Thanks for the help Lee.

Please Sign in or register to post replies

Write your reply to:

Draft