Copied to clipboard

Flag this post as spam?

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


  • Anthony Candaele 1197 posts 2049 karma points
    Jul 05, 2012 @ 14:58
    Anthony Candaele
    0

    check for last node in dynamicnodelist

    Hi,

    Is it possible in Razor to check if a node is the last node in a dynamicnodelist?

    This is my code:

    foreach (var id in networkitem.networkAssociatedMember)

                {

                    dynamic member = new DynamicNode(id.InnerText);

                    if (networkitem.networkAssociatedMember.Last())

                    {

                    @( member.nodeName);

                    }

                    else

                    {

                        @(member.nodeName + ", ");

                    }

                }

    As you can see to check if the node in the DynamicNodeList is the last node, I'm trying Last() , but this isn't working.

    thanks for your help,

    Anthony

  • Anthony Candaele 1197 posts 2049 karma points
    Jul 05, 2012 @ 15:07
    Anthony Candaele
    1

    Solved it, the methodname is: IsLast()

     

    @if(networkitem.HasValue("networkAssociatedMember"))

            {

                foreach (var id in networkitem.networkAssociatedMember)

                {

                    dynamic member = new DynamicNode(id.InnerText);

                    if (networkitem.networkAssociatedMember.IsLast())

                    {

                    @( member.nodeName);

                    }

                    else

                    {

                        @(member.nodeName + ", ");

                    }

                }

     

            }

  • Anthony Candaele 1197 posts 2049 karma points
    Jul 05, 2012 @ 15:23
    Anthony Candaele
    0

    Oops, seems like I was too optimistic. The method IsLast() isn't working, the condition is passed. 

  • Anthony Candaele 1197 posts 2049 karma points
    Jul 05, 2012 @ 15:43
    Anthony Candaele
    0

    ok, I found documentation about the IsLast() method of the DynamicNode object:

    Umbraco Razor Feature Walkthrough–Part 7

    However, when I try this code:

    foreach (var id in networkitem.networkAssociatedMember)

                {

                    DynamicNode member = new DynamicNode(id.InnerText);

                    if (member.IsLast())

                    {

                        @(member.Name);

                    }

                    else

                    {

                     @(member.Name + ", ");

                    }

                }

    This condition that checks if a DynamicNode is the last in the set is still passed, so that the outcome is rendered like this:

    (associatedmember, associatedmember,)

    while it should be

    (associatedmember, associatedmember)

    why is this not working?

    thanks for your help,

    Anthony

  • Fuji Kusaka 2203 posts 4220 karma points
    May 15, 2013 @ 20:59
    Fuji Kusaka
    1

    Hi Anthony,

    Did you get this sorted ou ? Am having the same issue here

  • Anthony Candaele 1197 posts 2049 karma points
    Aug 08, 2013 @ 13:45
    Anthony Candaele
    0

    @Fuji, seems the IsLast() is the method to check if a dynamic is the last item in a collection. See also this post:

    http://our.umbraco.org/forum/developers/razor/33671-Display-last-item-from-media-folder

     

    greetings,

    Anthony

Please Sign in or register to post replies

Write your reply to:

Draft