Copied to clipboard

Flag this post as spam?

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


  • Greg 18 posts 38 karma points
    Jan 13, 2015 @ 21:55
    Greg
    0

    Razor - where contains NOT = something

    Hello,

    So I have a multiple dropdown picker, all works great. However I have a special page where I want items tagged with A but not B. So I can look for A, that works... but items tagged A and B also show. I want to make sure I get A but only if it's also NOT tagged B. A + C would be ok... but if B is one of the tags... I don't want it

    How do I do this in Razor? How would I build the rest of this query?

    var page in currentNode.Children.Where("Visible").Where("something.Contains(\"A\")")

  • Greg 18 posts 38 karma points
    Jan 13, 2015 @ 22:08
    Greg
    0

    here's the actual query...

    var stuff= Umbraco.Content(111).Children

                            .Where("Visible")

                            .Where("stuffTypes.Contains(\"Stuff A\")")

                           so I need the exclude here --->   .Where("stuffTypes.Contains(\"Stuff B\")")

                            .OrderBy("CreateDate desc");

  • Greg 18 posts 38 karma points
    Jan 13, 2015 @ 22:38
    Greg
    0

    I'd also like to note... I currently have a conditional inside my loop to hide the undesired items... but I would like a better query/collection. I'd like to do a count on the number of items in the collection for example.

  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    Jan 13, 2015 @ 23:27
    Jeavon Leopold
    0

    Hi Greg,

    Here's how I would approach this one:

    var stuff= Umbraco.Content(111).Children.Where("Visible && stuffTypes.CsvContains(@0) && !stuffTypes.CsvContains(@1)", "Stuff A", "Stuff B").OrderBy("CreateDate desc");
    

    Hope this makes sense?

    Jeavon

  • Greg 18 posts 38 karma points
    Jan 14, 2015 @ 18:40
    Greg
    0

    Thanks Jeavon... I'll be trying this our shortly, but yes... makes total sense. Thank you so much!

Please Sign in or register to post replies

Write your reply to:

Draft