0

I have a List of data I'm bringing into the Razor view and I'd like to filter it at this point. For some reason, the Where doesn't work when I:

@foreach (var t in Model.ToDoLists.Where(t => t.Status != "Complete" || t.Status != "Delete" || 
   t.Status != "delete"))

But, I can be silly and do this and it works:

@foreach (var t in Model.ToDoLists.Where(t => t.Status != "Complete").Where(b => b.Status != 
"Delete").Where(c => c.Status != "delete"))

What is the correct way to do this?

Thanks!

  • 2
    Join the conditions in the first example with AND (&&) not with OR (||) If the status is "DELETE" is, of course, different from "COMPLETE" – Steve Mar 11 '21 at 17:55
  • Does this answer your question? [C# If not (this) Or (this) or (this) - Multiple condition IF/OR](https://stackoverflow.com/questions/39580337/c-sharp-if-not-this-or-this-or-this-multiple-condition-if-or) – haldo Mar 11 '21 at 18:51

1 Answers1

0

As Steve said,you can use && rather than ||,and you can use ToLower,so that you don't need to check Delete:

@foreach (var t in Model.ToDoLists.Where(t => t.Status != "Complete"&& t.Status.ToLower() != "delete"))
Yiyi You
  • 16,875
  • 1
  • 10
  • 22