Copied to clipboard

Flag this post as spam?

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


  • Chris 10 posts 40 karma points
    Apr 18, 2012 @ 23:38
    Chris
    0

    Find descendants where property equals...

    I must be overlooking something incredibly simple:

     

    All I want to do is output a list of any content nodes where a certain property is true.

    <ul>
    @foreach (var item in @Model.Children.Where("certainProperty = true"))
    {
    <li>@item.Name</a></li>
    }
    </ul>

    ... Works just fine for the Children of the current node. (Obviously).

     

    However,

    <ul>
    @foreach (var item in @Model.Descendants.Where("certainProperty = true"))
    {
    <li>@item.Name</a></li>
    }
    </ul>

    ... Outputs nothing.

     

    What am I missing?

  • Douglas Ludlow 210 posts 366 karma points
    Apr 19, 2012 @ 00:08
    Douglas Ludlow
    0

    Using the Where clause you can just use the boolean value as follows:

    Model.Descendants.Where("certainBooleanProperty")

     

  • Chris 10 posts 40 karma points
    Apr 19, 2012 @ 00:19
    Chris
    0

    Thank you - but I'm still having the same problem.

    Either way, "Children" works, but "Descendants" does not.

     

  • Douglas Ludlow 210 posts 366 karma points
    Apr 19, 2012 @ 00:22
    Douglas Ludlow
    1

    You may try using Descendants as a method:

    Model.Descendants().Where("certainBooleanProperty")
  • Chris 10 posts 40 karma points
    Apr 19, 2012 @ 00:25
    Chris
    0

    That did it - thank you very much!

Please Sign in or register to post replies

Write your reply to:

Draft