Copied to clipboard

Flag this post as spam?

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


  • Michael Nielsen 153 posts 810 karma points
    Apr 27, 2015 @ 08:40
    Michael Nielsen
    0

    Using Skip() on a string array

    I am pulling af comma-separated list from a multiple media picker.
    This get's me: "1111,4444,8888".

    I want to foreach the list (and skip the first image), so I can get the media URL's - I am doing that by splitting:

    @foreach(var test in CurrentPage.images.Split(',').Skip(1)){
      @test.Url
    }

    I then get an Exception error:

    Microsoft.CSharp.RuntimeBinder.RuntimeBinderException: 'System.Array' does not contain a definition for 'Skip'

    How can I use Skip(), Take() and so on, when I foreach a splitted comma-separated list?

     

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Apr 27, 2015 @ 08:50
    Dennis Aaen
    101

    Hi Ørskov Gruppen A/S,

    Try to see the documentation about using the multiple media picker https://our.umbraco.org/documentation/using-umbraco/backoffice-overview/property-editors/Built-in-Property-Editors-v7/Media-Picker. I think I would do it like this. So I add the skip to the foreach loop.

    @if (CurrentPage.HasValue("caseStudyImages"))
    {
        var caseStudyImagesList = CurrentPage.CaseStudyImages.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
        var caseStudyImagesCollection = Umbraco.Media(caseStudyImagesList);

        foreach (var caseStudyImage in caseStudyImagesCollection.Skip(1))
        {
            <img src="@caseStudyImage.Url" style="width:300px;height:300px" />
        }
    }

    Hope this helps,

    /Dennis

Please Sign in or register to post replies

Write your reply to:

Draft