Copied to clipboard

Flag this post as spam?

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


  • Craig100 1136 posts 2523 karma points c-trib
    Mar 06, 2015 @ 20:50
    Craig100
    0

    Reversed bool on checkbox

    Umb 7.2.2

    In a menu partial I'm looking for all children of the web root that are visible and have their "showInTop" checkbox checked. The code seems to work the opposite way around though, and it's bugging me as to why.

    To get the pages to show withe showInTop checked I have to negate the term (!x.GetPropertyValue<bool>).

    if(Model.Content.AncestorOrSelf().Children.Where(x => x.IsVisible() && !x.GetPropertyValue<bool>("showInTop")).Any()){

    If I don't negate the term, nothing shows.

    I'm converting to Strongly Typed from Dynamic. The Dynamic version that worked is:

    if (home.Children.Where("Visible && showInTopMenu == @0",true).Any()) {

    Any clue appreciated,

    Craig

  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    Mar 06, 2015 @ 20:55
    Jeavon Leopold
    101

    Hi Craig,

    You seem to know it already but you should not need that ! (you can combine the Where and Any also)

    if (Model.Content.AncestorOrSelf().Children.Any(x => x.IsVisible() && x.GetPropertyValue<bool>("showInTop")))
    

    So is this always false?

    Jeavon

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Mar 06, 2015 @ 21:03
    Dennis Aaen
    0

    Hi Craig,

    What if you are doing something like this

    if(Model.Content.AncestorOrSelf().Children.Where(x => x.IsVisible()).Any(x => x.GetPropertyValue<bool>("showInTop") == "1")){

    }

    Hope this helps,

    /Dennis

  • Craig100 1136 posts 2523 karma points c-trib
    Mar 06, 2015 @ 21:09
    Craig100
    0

    Thanks for the tip on combining the Where and Any.  The other was another typo (hangs head in shame) "showInTop" should have been "showInTopMenu".

    Craig

  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    Mar 06, 2015 @ 21:13
    Jeavon Leopold
    0

    Ah, happens to everyone all the time! Glad you've got it working now!

Please Sign in or register to post replies

Write your reply to:

Draft