title: Filter Field in List by boolean value in MVC
body: <p>I had help filtering a Foreach loop in my view and I figured I would use that reasoning to now filter a field using the same logic.  I need this field to show the last TicketNoteDate that has a PublicFlag == true.  The code compiles but it crashes when I try to run it.  Here is the code I tried:</p>
  
  <pre><code>@Html.DisplayFor(modelItem =&gt; item.TicketNotes.OrderBy(t =&gt; t.TicketNoteDate).Where(t =&gt; t.PublicFlag == true).Last().TicketNoteDate)
  </code></pre>
  
  <p>and here is the error I received:</p>
  
  <blockquote>
    <p>An exception of type 'System.InvalidOperationException' occurred in
    System.Core.dll but was not handled in user code</p>
  </blockquote>
  
  <p>If I remove this code:</p>
  
  <pre><code>.Where(t =&gt; t.PublicFlag == true)
  </code></pre>
  
  <p>then it works except for of course the filtering out non public notes.</p>