Copied to clipboard

Flag this post as spam?

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


  • Carlos Mosqueda 241 posts 432 karma points
    Sep 24, 2015 @ 17:20
    Carlos Mosqueda
    0

    Umbraco 7. Multinode tree picker skip nodes that no longer exist

    In Umbraco 7, we have a Mulitnode tree picker on a node. We choose a different node with the MNTP. We then delete the picked node out of the Umbraco tree, but NOT out of the MNTP on the original node. In C# how would we loop through the MNTP and check to see if the chosen node in the MNTP exists anymore?

  • Marc Goodson 2149 posts 14377 karma points MVP 9x c-trib
    Sep 25, 2015 @ 23:55
    Marc Goodson
    0

    Hi Carlos

    Presuming you are getting the IPublishedContent for each picked item, you can filter out any nulls returned by Umbraco.TypedContent:

    eg

    If your Multinode Tree Picker is called 'RelatedContent' and you are storing picked items as CSV:

    if (Model.Content.HasProperty("RelatedContent") && Model.Content.HasValue("RelatedContent"))
    {
    // get selected ids
            var nodeIds = Model.Content.GetPropertyValue<string>("RelatedContent").Split(new[] { "," }, StringSplitOptions.RemoveEmptyEntries)
                        .Select(int.Parse);
            // turn ids into IPublishedContent, filter out nulls
            var relatedContentNodes = Umbraco.TypedContent(nodeIds).Where(x => x != null);
    }
    
  • Dave Woestenborghs 3504 posts 12134 karma points MVP 9x admin c-trib
    Sep 26, 2015 @ 10:27
    Dave Woestenborghs
    0

    If you install this package this will be handled for you : https://our.umbraco.org/projects/developer-tools/umbraco-core-property-value-converters/

    You will then do this in your code :

    @inherits UmbracoViewPage
    @{
        var items = Model.GetPropertyValue<IEnumerable<IPublishedContent>>("yourPropertyName").ToList();
    }
    
    @foreach(var item in items){
        <p>@item.Name</p>
    }
    

    This will return a list of only publish items from your picker

    Dave

Please Sign in or register to post replies

Write your reply to:

Draft