Copied to clipboard

Flag this post as spam?

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


  • Ayo Adesina 370 posts 926 karma points
    Jun 16, 2015 @ 14:22
    Ayo Adesina
    1

    Getting Id's from Multinode Tree Picker

    I'm trying to get the id's of the nodes selected using the Multinode Tree Picker

    Currently this is what I have

    var Result = node.GetPropertyValue("propertyName").ToString()
    

    Result ends up being.

    <MultiNodePicker type=\"content\"><nodeId>2202</nodeId><nodeId>2203</nodeId><nodeId>2204</nodeId></MultiNodePicker>
    

    The Id's are in the result, but this method is returning xml. as well, I'm using umbraco 6 - I don't really want to have to start extracting the number from the string, or covert it in to a xml document....

    is there a way I can just force umbraco to give me CSV so in this example I get

    2202, 2203

    ?

    Thanks Ayo

  • Ayo Adesina 370 posts 926 karma points
    Jun 16, 2015 @ 14:45
    Ayo Adesina
    0

    Found the answer to my question so I just thoght I'd post the answer just in case someone else has the same problem.

    On the definition of my Multinode Tree Picker, there is a option of how the values are stored.

    If you select CSV - problem solved.

    See screen shot

    enter image description here

  • Ismail Mayat 4288 posts 9247 karma points MVP 2x admin c-trib
    Jun 16, 2015 @ 14:53
    Ismail Mayat
    1

    Ayo,

    Umbraco core property convertors are your friend https://our.umbraco.org/projects/developer-tools/umbraco-core-property-value-converters/

    So you can then do

     @{
        IEnumerable<IPublishedContent> typedMultiNodeTreePicker = Model.Content.GetPropertyValue<IEnumerable<IPublishedContent>>("propertyName");
        foreach (IPublishedContent item in typedMultiNodeTreePicker)
        {       
            <p>@item.Name</p>           
        }       
    }
    

    It will convert everything for you.

    Regards

    Ismail

  • Ayo Adesina 370 posts 926 karma points
    Jun 16, 2015 @ 15:12
    Ayo Adesina
    0

    I only needed the id's so changing the data-type definition worked quite well for me.

    I was aware of the GetPropertyValue<> conversion thing, but in my mind I had never thought about coveting to IPublished content, I just used it to do things like bool, and int, but yes your right!

    That's one for the tool box... ill be using that in future!

    Thanks Ayo

  • Niels Lyngsø 21 posts 99 karma points hq
    Mar 12, 2018 @ 15:12
    Niels Lyngsø
    0

    Is there any way to get the Ids without getting the IPublishedContent objects?

    I would like to do something like this, but this does not work for me:

    var Result = node.GetPropertyValue<IEnumerable<int>>("propertyName")
    
Please Sign in or register to post replies

Write your reply to:

Draft