Copied to clipboard

Flag this post as spam?

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


  • keilo 568 posts 1023 karma points
    May 02, 2017 @ 16:38
    keilo
    0

    7.6 Umbraco.MultiNodeTreePicker

    Following the update from 7.5.8 to 7.6 it seems the following code doesnt iterate as used to (no changes to data type or else);

    Get nodes where no member selected (i.e. mntp selection empty):

     foreach (var node in 
    
    nodes.Descendants("articles").Where("member==\"\"").OrderBy("CreateDate desc")) 
    {
        //.. show entries
        }
    

    How can I check if MNTP is empty (member in example above) within the foreach clause?

  • Paul Wright (suedeapple) 277 posts 704 karma points
    May 02, 2017 @ 16:44
    Paul Wright (suedeapple)
    1

    Perhaps checking if its "null", or "String.IsNullOrEmpty"

  • keilo 568 posts 1023 karma points
    May 02, 2017 @ 16:57
    keilo
    0

    Hi Paul

    I think something has changed, I cant use the same old code to iterate nodes where the MNTP is not selected;

    • .Where("member==\"\"")
    • .Where("member==null")
    • .Where("member==string.IsNullOrEmpty")

    None of the above iterates. It was working fine before the upgrade to 7.6 (at 7.5.8)

    I have republished the site/cache and rebuilt indexes but didnt help.

    This should be easy but I cant seem to think of a solution...

  • Paul Wright (suedeapple) 277 posts 704 karma points
    May 02, 2017 @ 17:05
    Paul Wright (suedeapple)
    1

    Something more like this perhaps...

        @foreach (var node in nodes.Descendants("articles").Where(x => string.IsNullOrEmpty(x.GetPropertyValue<string>("member"))).OrderByDescending(x => x.CreateDate)
    {
       @node.Name
    }
    
  • keilo 568 posts 1023 karma points
    May 02, 2017 @ 17:11
    keilo
    0

    Hi again Paul

    That gives the exception:

    Cannot use a lambda expression as an argument to a dynamically dispatched operation without first casting it to a delegate or expression tree type
    

    I have nodes declared like;

     var nodes = Umbraco.Content(1492);
    

    I cant understand why it stopped working after the update to 7.6, not well versed with lambda expressions.

  • Paul Wright (suedeapple) 277 posts 704 karma points
    May 02, 2017 @ 17:14
    Paul Wright (suedeapple)
    1

    I'll assume its a "content" node. Change your var nodes line to use :

    var nodes = Umbraco.TypedContent(1492);
    

    lambda makes things a whole lot easier, and you get Intellisense support in Visual Studio.

    Just ensure you're using Strongly Typed Methods, and not over using dynamics (eurgh)

  • keilo 568 posts 1023 karma points
    May 02, 2017 @ 17:21
    keilo
    0

    Yes a content node. Thanks for the heads up, I'll be reading more on lambda.

    However I get exception

    Delegate 'System.Func<Umbraco.Core.Models.IPublishedContent,int,bool>' does not take 1 arguments
    

    with following code;

    var nodes= Umbraco.TypedContent(1492);
               foreach (var node in nodes.Descendants("articles").Where(x => string.IsNullOrEmpty(x.GetPropertyValue("member"))).OrderByDescending(x => x.CreateDate)){
    
                    <p>@node.Name</p>
                };
    
  • Paul Wright (suedeapple) 277 posts 704 karma points
    May 02, 2017 @ 17:29
    Paul Wright (suedeapple)
    100

    Ahh you may want to look at

    <!-- Enables value converters for all built in property editors so that they return strongly typed object, recommended for use with Models Builder -->
    <EnablePropertyValueConverters>true</EnablePropertyValueConverters>
    

    And setting this to false - so you get the "Legacy" nodes as a string, and not as iPublishedContent

  • keilo 568 posts 1023 karma points
    May 02, 2017 @ 17:39
    keilo
    0

    Paul you are a gentleman and scholar!

    That was it, it was set to true. Changing to false made it work.

    I have some reading to do I guess, need to catch up...

    Many thanks for your time!

Please Sign in or register to post replies

Write your reply to:

Draft