Copied to clipboard

Flag this post as spam?

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


  • webmonger 130 posts 265 karma points
    May 17, 2011 @ 15:54
    webmonger
    0

    @Model.Ancestors().Where() problem

    Hi

    I've got a problem with the where method on the Ancestors collection.

    I've got a look that just loops all parent items which works.

    @foreach (var parent in @Model.Ancestors().Where("umbracoNaviHide != true"))
    {
    <li><a href="@parent.Url">@parent.Name</a></li>
    }

    I've now modified the code to get only Ancestors where Level > 2

    @foreach (var parent in @Model.Ancestors().Where("Level > 2 && umbracoNaviHide != true"))
    {
    <li><a href="@parent.Url">@parent.Name</a></li>
    }

    According to the post Razor features walkthough 4 you can do multiple commands in a where by adding || (or) or && (and)

    I'm totally lost on this one any help would be great.

    Cheers

    Jon

  • webmonger 130 posts 265 karma points
    May 17, 2011 @ 15:58
    webmonger
    0

    May help if you know what error I receive!

    Error loading Razor Script NavigationLeft.cshtml

    Incorrect number of parameters supplied for lambda declaration

  • Lee 1123 posts 3059 karma points
    May 17, 2011 @ 16:00
    Lee
    0

    I got round multiple wheres by doing multiple wheres

    i.e .where("Level > 2").where("Visible")

     

  • Lee 1123 posts 3059 karma points
    May 17, 2011 @ 16:02
    Lee
    0

    Actually I did it the other way round in my code .Where("Visible").Where("Level > 2") but don't know if that will make a difference

  • jaygreasley 416 posts 403 karma points
    May 17, 2011 @ 16:02
    jaygreasley
    0

    nice idea Lee, reads better as well..

    (May have a slight performance hit but I don't know enough about the internals)

  • Mark Johnston 59 posts 111 karma points
    May 17, 2011 @ 16:09
    Mark Johnston
    0

    I also found I had to do it this way in 4.7.0 with the multiple Where's

  • Robert Foster 440 posts 1684 karma points MVP admin c-trib
    May 17, 2011 @ 18:12
    Robert Foster
    0

    There's a problem with the code in 4.7 that breaks Where() and OrderBy() - it's a known issue and apparently will be fixed... see http://our.umbraco.org/forum/developers/razor/18373-DynamicNodeListWhere-marked-as-private-in-47final?p=1

  • 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