Copied to clipboard

Flag this post as spam?

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


  • bh 444 posts 1544 karma points
    Jan 26, 2023 @ 16:48
    bh
    0

    How to Filter Block List Items

    I have a block list of Points of Interest (POI). Each POI has a name, url, category, address. I want to filter the blocklist by category. Is this possible? How?

    I've tried a bunch of different ways. This is the closest I've gotten, but it doesn't work.

    var POIlist = content.PointsOfInterest.Select(x => (CPoi)x.Content);
    var POIfood = POIlist.Where(x => x.Value<string>("category").Contains("food"));
    

    With this code POIfood is empty. Should contain 3 items of type CPoi.

  • Julien Kulker 75 posts 427 karma points c-trib
    Jan 27, 2023 @ 07:50
    Julien Kulker
    0

    Hi bh,

    Can you try below if i am correct you are using the modelsbuilder so below is a example:

    var POIlist = content.LandingCards.Select(x => (UmbracoModels.LandingCard)x.Content);
    var filteredLandingcards = POIlist.Where(x => x.Title.Contains("foodItem"));
    

    Tested above code so this should work. For you the coude would look something like this

    var POIlist = content.PointsOfInterest.Select(x => (CPoi)x.Content);
    var POIfood = POIlist.Where(x => x.Category.Contains("food"));
    

    Let me know if it worked. It should work

  • bh 444 posts 1544 karma points
    Jan 27, 2023 @ 13:19
    bh
    0

    @JulienKulker I actually started with x.Category.Contains, but that threw an error. Lemme get that error message for you...

    'CPoi' does not contain a definition for 'Category' and no accessible extension method 'Category' accepting a first argument of type 'CPoi' could be found (are you missing a using directive or an assembly reference?)

    var POIlist = content.PointsOfInterest.Select(x => (CPoi)x.Content);
    var POIfood = POIlist.Where(x => x.Category.Contains("food"));
    

    NOTE: CPoi is an element type that has Category as an attribute (dropdown list property editor). Also, due to models builder Category comes up in intellisense. The code feels right, but it's throwing that mean ole error!

  • Dave Woestenborghs 3504 posts 12135 karma points MVP 9x admin c-trib
    Jan 27, 2023 @ 07:56
    Dave Woestenborghs
    0

    Hi bh,

    What kind of property editor is category on your POI item.

    Dave

  • bh 444 posts 1544 karma points
    Jan 27, 2023 @ 13:12
    bh
    0

    @DaveWoestenborghs Dropdown list.

  • Dave Woestenborghs 3504 posts 12135 karma points MVP 9x admin c-trib
    Jan 27, 2023 @ 13:30
    Dave Woestenborghs
    0

    Hi bh,

    What are the values of the Dropdownlist.

    Dave

  • bh 444 posts 1544 karma points
    Jan 27, 2023 @ 13:31
    bh
    1

    I got it working. User error on my part...I had to rebuild after creating my CPoi. I thought I'd already done that. Color me embarrassed. Thanks for your replies @Dave & @Julien

Please Sign in or register to post replies

Write your reply to:

Draft