Copied to clipboard

Flag this post as spam?

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


  • Brett Fullam 119 posts 629 karma points
    May 08, 2017 @ 17:13
    Brett Fullam
    0

    Media Picker Dynamic foreach loop not working? (Umbraco v7.6)

    I can't get even the most basic of examples running using the Media Picker "Dynamic" example supplied in umbraco.org's media picker documentation.

    I keep getting this error:

    System.Collections.Generic.List

    I can get the "Typed" version to work without any issues, but only if the media picker does NOT allow multiple items to be checked. After a long and exhausting search I still cannot find a solution.

    Here's a copy of the code I'm working with:

    @if (CurrentPage.HasValue("sliderPictures"))
    {
        var caseStudyImagesList = CurrentPage.sliderPictures.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
        var caseStudyImagesCollection = Umbraco.Media(caseStudyImagesList);
    
        foreach (var sliderPictures in caseStudyImagesCollection)
        {
            <img src="@sliderPictures.Url"/>
        }
    }
    

    Anyone else having this issue ...? Any help would be appreciated.

    -- Brett

  • Brett Fullam 119 posts 629 karma points
    May 08, 2017 @ 18:00
    Brett Fullam
    102

    UPDATE ... I managed to find a related thread with both the "cause" and the "solution" ... thanks to Josh Bula and Jamie Pollack this has been resolved ... see below:

    Here's my updated code block that WORKS (so you can see the applied edits):

    @if (Model.Content.HasValue("sliderPictures"))
    {
        var caseStudyImagesCollection = Model.Content.GetPropertyValue<IEnumerable<IPublishedContent>>("sliderPictures");
    
        foreach (var sliderPictures in caseStudyImagesCollection)
            {      
                <img src="@sliderPictures.Url" style="width:300px;height:300px" />      
            }                                                               
    }
    

    Here's a link to the related thread that I found both the answer AND an explanation as to why this is happening in Umbraco v7.6:

    https://our.umbraco.org/forum/templates-partial-views-and-macros/85128-media-picker-in-76-rc-input-string-was-not-in-a-correct-format

    The only thing they didn't do is include a sample code block with the solution applied (which is now listed above).

    I hope this helps!

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

    Continue discussion

Please Sign in or register to post replies