Copied to clipboard

Flag this post as spam?

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


  • Jules 276 posts 587 karma points
    Mar 22, 2014 @ 14:13
    Jules
    0

    Filtering Children with LINQ and GetPropertyValue

    Using V 6.1.6.

    I am trying to filter children of the current node in my View and I was hoping to do something like below using LINQ but the code will not compile because the GetPropertyValue is unrecognised.

    Umbraco.TypedContent(CurrentPage.Id).Children.Where(n => 
    String.Equals(n.GetPropertyValue<string>("cat1"), formCat1, StringComparison.CurrentCultureIgnoreCase) ||
    String.Equals(n.GetPropertyValue<string>("cat2"), formCat2, StringComparison.CurrentCultureIgnoreCase) ||
    String.Equals(n.GetPropertyValue<string>("cat3"), formCat3, StringComparison.CurrentCultureIgnoreCase));

    I get a

    CS1977: 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 seen a few other topics in the forum where the above works (GetProperty within a lambda).  What am I missing? How would you usually filter a list of this type either in a  view or in a partial view?

    J

  • Jeroen Breuer 4908 posts 12265 karma points MVP 5x admin c-trib
    Mar 22, 2014 @ 20:31
    Jeroen Breuer
    100

    Hello,

    You are using CurrentPage.Id which is dynamic and that's why extension methods wont' work.

    Try something like this:

    Model.Content.Children.Where(n => 

    Jeroen

  • Jules 276 posts 587 karma points
    Mar 23, 2014 @ 00:28
    Jules
    0

    Yep that was it.

    Just added

    int pageId = CurrentPage.Id;
    

    And then used

    Umbraco.TypedContent(pageId).Children....
    

    Thanks

    J

Please Sign in or register to post replies

Write your reply to:

Draft