Copied to clipboard

Flag this post as spam?

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


  • Marc-André 63 posts 279 karma points
    Apr 09, 2019 @ 21:08
    Marc-André
    0

    Help with querying

    Hello. I'm new to Umbraco. I tried to get every pages with a boolean value to true but I don't seems to get it right. Here's my code right now :

    @{
      var selection = Umbraco.ContentAtRoot().FirstOrDefault().Children().Where(x => x.GetProperty("menu").Value = true);
    }
    

    I've also tried .GetPropertyValue

    Thanks for your help!

  • Nigel Wilson 945 posts 2077 karma points
    Apr 10, 2019 @ 00:02
    Nigel Wilson
    0

    Hi Marc-Andre

    I assume the property "menu" is a toggle (Yes/No)

    If so then try

    x => x.GetPropertyValue<bool>("menu").Value == true
    

    You do need the double equals, and cast the property as a bool.

    If this doesn't work then maybe this

    x => Convert.ToBoolean(x.GetProperty("menu").Value) == true
    

    Cheers

    Nigel

  • Marc-André 63 posts 279 karma points
    Apr 10, 2019 @ 12:21
    Marc-André
    0

    Hi Nigel,

    Yes menu is a "checkbox" type.

    Both of them don't work :(

    var selection = Umbraco.ContentAtRoot().FirstOrDefault().Children().Where(x => x.GetPropertyValue<bool>("menuUtil").Value == true);
    

    Error : 'IPublishedContent' does not contain a definition for 'GetPropertyValue' and no accessible extension method 'GetPropertyValue' accepting a first argument of type 'IPublishedContent' could be found

    var selection = Umbraco.ContentAtRoot().FirstOrDefault().Children().Where(x => Convert.ToBoolean(x.GetProperty("menuUtil").Value) == true);
    

    Argument 1: cannot convert from 'method group' to 'object'

  • Corné Strijkert 80 posts 456 karma points c-trib
    Apr 10, 2019 @ 12:36
    Corné Strijkert
    100

    Hi Marc-Andre,

    In Umbraco 8 the GetPropertyValue() method is not available anymore.

    Instead you have to use the Value() method. So, applied to your situation:

    @Model.Root().Children.Where(x => x.Value<bool>("menu"))
    
  • Marc-André 63 posts 279 karma points
    Apr 10, 2019 @ 12:43
    Marc-André
    0

    YES! Thanks a lot Corné!

Please Sign in or register to post replies

Write your reply to:

Draft