Copied to clipboard

Flag this post as spam?

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


  • Mark Evans 86 posts 116 karma points
    Sep 15, 2014 @ 11:38
    Mark Evans
    0

    checking for a boolean value

    i m trying to add a check for a boolean value in my code.

    this works ok

    var widgets = currentPage.Children.Where(x => x.DocumentTypeAlias == "widgetFolder").First().Children;

    but now that i need to put these widgets in 2 separate areas of the page i added a new property (is WidgetInTheBanner) which is a True/False field.....

    When i try

    var widgets = currentPage.Children.Where(x => x.DocumentTypeAlias == "widgetFolder" && !x.GetPropertyValue<bool>("isWidgetInTheBanner")).First().Children;

    i get an error  - Sequence contains no elements - so i presume this statement is incorrect format....

     

  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    Sep 15, 2014 @ 11:52
    Jeavon Leopold
    0

    Not really a format error but First is not getting anything, to make it more resilient, try this:

    var widgets = Model.Content.Children.FirstOrDefault(x => x.DocumentTypeAlias == "widgetFolder" && !x.GetPropertyValue<bool>("isWidgetInTheBanner"));
    if (widgets != null)
    {
        var somethingelse = widgets.Children;
    }
    
  • Mark Evans 86 posts 116 karma points
    Sep 15, 2014 @ 12:27
    Mark Evans
    0

    thanks

    it still doesnt seem to be recognising the boolean value, some items ive set to true are still appearing....

     

  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    Sep 15, 2014 @ 12:33
    Jeavon Leopold
    0

    sorry I changed your currentPage to Model.Content to test

    var widgets = currentPage.Children.FirstOrDefault(x => x.DocumentTypeAlias == "widgetFolder" && !x.GetPropertyValue<bool>("isWidgetInTheBanner"));
    if (widgets != null)
    {
        var somethingelse = widgets.Children;
    }
    
Please Sign in or register to post replies

Write your reply to:

Draft