Copied to clipboard

Flag this post as spam?

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


  • Kurisotofa 27 posts 75 karma points
    Aug 27, 2016 @ 15:59
    Kurisotofa
    0

    IEnumerable<IPublishedContent> ElementAt(index) method

    I declared :

    IEnumerable<IPublishedContent> mediaNodeList = Umbraco.TypedMedia(mediaNodeIds)

    Resulting in an IEnumerable collection of media nodes. I know that the collection does contain elements, because the .Count() method reports 2 elements.

    However, the following code :

    IPublishedContent myMedia = mediaNodeList.ElementAt(1);

    results in the following error :

    Specified argument was out of the range of valid values. Parameter name: index

    And I have no idea why...

    Again, any help would be appreciated!

  • Lucio 24 posts 142 karma points
    Aug 30, 2016 @ 10:41
    Lucio
    0

    This should work:

    List<IPublishedContent> mediaNodeList = Umbraco.TypedMedia(mediaNodeIds).ToList();
    
        IPublishedContent myMedia;
        if (mediaNodeList.Count >= 2)
        {
            myMedia = mediaNodeList[1];
        }
    
  • 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.

Please Sign in or register to post replies