Copied to clipboard

Flag this post as spam?

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


  • Michaël Vanbrabandt 863 posts 3343 karma points c-trib
    Oct 31, 2016 @ 14:54
    Michaël Vanbrabandt
    0

    Check if multi content node property has id

    Hi all,

    is there a quick utility function to check if an id is present in the muli content node property?

    For instance I have a published content node of type Company which has a property called Categories which is a multi node content picker.

    For example it has the value "1067, 1066".

    Now in my code I need to check if an id is present in here.

    Anyone that can help me?

    /Michaël

  • Frans de Jong 522 posts 1762 karma points c-trib
    Oct 31, 2016 @ 15:43
    Frans de Jong
    0

    If you'r talking about the Multinode treepicker I'd do the following.

    I always assume if no Id is picked the length of the comma separated string is empty. Therefore there's no Id in it. If you pick a node than it will contain a Id.

    So if you just want to check if there is one or more Id's in the picker I'd do a

    if (!picker.IsNullOrEmpty){
    do stuff...
    }
    
  • Michaël Vanbrabandt 863 posts 3343 karma points c-trib
    Oct 31, 2016 @ 15:48
    Michaël Vanbrabandt
    0

    Hi Frans,

    I need to check if an id is set in the multi node value. So if in my backoffice I have assigned 2 nodes to my property the value of this property will be something like "1067,1066". So the ids of the nodes selected.

    Now in my code I have an id and I need to check this if this is a selected node of the property.

    /Michaël

  • Frans de Jong 522 posts 1762 karma points c-trib
    Oct 31, 2016 @ 15:59
    Frans de Jong
    100

    Ah, sorry I misunderstood you.

    I always use Linq (using System.Linq)

    if(picker.Split(',').Contains("Id.ToString()")){
    
    }
    

    Notice the single quotes behind the Split. If you use double quotes it wont work.

  • Michaël Vanbrabandt 863 posts 3343 karma points c-trib
    Nov 01, 2016 @ 10:41
    Michaël Vanbrabandt
    0

    Hi Frans,

    thanks for this solution!

    /Michaël

  • 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