Copied to clipboard

Flag this post as spam?

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


  • Josh Bula 13 posts 75 karma points
    Apr 11, 2017 @ 18:36
    Josh Bula
    0

    Media Picker in 7.6 RC - Input string was not in a correct format

    Following the example in the documentation for the Media Picker, I have this code trying to retrieve and display multiple images uploaded to the page through the new Media Picker:

        @if (Model.Content.HasValue("slideshowImages"))
        {
            var imagesList = Model.Content.GetPropertyValue<string>("slideshowImages").Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries).Select(int.Parse);
            var imagesCollection = Umbraco.TypedMedia(imagesList).Where(x => x != null);
            foreach (var imageItem in imagesCollection)
            {
                <div class="abnner_slider_img" style="background-image: url('@imageItem.Url');"> </div>
            }
        }
    

    On the foreach line, it throws an "Input string was not in a correct format" error.

    If also throws the same error if I try to get a count of the images by doing either imagesList.Count() or imagesCollection.Count()

    Has something changed for 7.6 that breaks this?

  • Jamie Pollock 172 posts 836 karma points c-trib
    Apr 11, 2017 @ 19:17
    Jamie Pollock
    103

    Hi Josh,
    One of the improvements for v7.6 is the inclusion of the rather fantastic Core Property Value Converters community package into the core.

    This means your slideshowImages can automatically be accessed as follows:

    Model.Content.GetPropertyValue<IEnumerable<IPublishedContent>>("slideshowImages")
    

    So there should be no need for Umbraco.TypedMedia call.

    I hope this helps :)

    Thanks,
    Jamie

  • Josh Bula 13 posts 75 karma points
    Apr 11, 2017 @ 19:40
    Josh Bula
    1

    Thanks Jamie, that worked perfectly!

  • Jamie Pollock 172 posts 836 karma points c-trib
    Apr 11, 2017 @ 19:44
    Jamie Pollock
    0

    Fantastic :)

Please Sign in or register to post replies

Write your reply to:

Draft