Copied to clipboard

Flag this post as spam?

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


  • Anton 36 posts 67 karma points
    Sep 08, 2012 @ 18:06
    Anton
    0

    How to retrieve nodeId from MNTP?

    I've got the following items in my MTNP:

    I'm trying various code to try and retrieve the nodeIds without any success.  I'm going along the route of:

    foreach(var v in Model.TopPicksRepository.Items.Children)

    foreach(var v in Model.TopPicksRepository.Items.MultiNodePicker.Children)

    Can anyone point me in the right direction?

  • Hendy Racher 863 posts 3847 karma points MVP 2x admin c-trib
    Sep 08, 2012 @ 18:25
    Hendy Racher
    0

    Hi Anton,

    There's a hepler method in uQuery (GetNodesByXml) to get a collection of the selected nodes from an MNTP xml fragment:

    Node currentNode = uQuery.GetCurrentNode();
    string xml = currentNode.GetProperty<string>("TopPicksRepository");
    
    foreach(Node pickedNode in uQuery.GetNodesByXml(xml))
    {
      ...
    }
    

     

    HTH,

    Hendy

  • Ernst Utvik 123 posts 235 karma points
    Sep 08, 2012 @ 23:05
    Ernst Utvik
    0

    The following should list the items/id's in a MNTP with the alias TopPicksRepository.

    @foreach (var x in Model.TopPicksRepository){ @x.InnerText }

  • Anton 36 posts 67 karma points
    Sep 09, 2012 @ 04:46
    Anton
    0

    The code by Hendy works great - Thanks.

    However i can't help but notice the simplicity of Ernst's example which unfortunately doesn't work - In debug mode i can only see that the TopPicksRepository node and not the "items" under it.

    @foreach (var item in Model.TopPicksRepository){<li>@item.InnerText</li>}

    This doesn't work either.

    @foreach (var item in Model.TopPicksRepository.items)
        {
            <li>@item.InnerText</li>        
        }
  • Troels Larsen 75 posts 280 karma points
    Sep 09, 2012 @ 10:44
    Troels Larsen
    0

    i like to keep my C# away from my razor view so i got a clean and nice view, just because razor can hold all your logic code there is no excuse for mixing presentation and logic 

    if u dont need some filtering on u items u could just use 

    public static DynamicNodeList MultiNodePicker(this RazorLibraryCore library, DynamicXml dynamicXml)
            {
                var list = new DynamicNodeList();
                foreach (dynamic item in dynamicXml)
                {
                    list.Add(new DynamicNode(item.InnerText));
                }
                return list;

     

            }

     

     

    if u need some filtering on your nodes make a normal static extension that dont work on the RazorLibraryCore but still passes the the dynamicXml, do the filtering there and returns your filtered nodelist that way u can have a clean foreach loop where u pressentation dont have to test for empty string and what not :) 

     

     

Please Sign in or register to post replies

Write your reply to:

Draft