title: Search by multiple fields
body: <p>I'm working on a project and implemented a search by multiple fields in MVC, using LINQ like so:</p>
  
  <pre><code>public ActionResult SearchResult(SearchViewModel model)
  {
      List&lt;Requisition&gt; emptyList = new List&lt;Requisition&gt;();
  
      if (model.RequisitionID &gt; 0 
          || model.Department &gt; 0 
          || model.Status &gt; 0
          || model.RequisitionedBy != null)
      {
          var results = db.Requisitions.Where(x =&gt; x.RequisitionId &gt; 0);
  
          results = ProcessSearchInput(model, results);
  
          return PartialView(results.ToList());
      }
  
      return PartialView(emptyList);
  }
  </code></pre>
  
  <p>Helper:</p>
  
  <pre><code>private static IQueryable&lt;Requisition&gt; ProcessSearchInput(SearchViewModel model, IQueryable&lt;Requisition&gt; results)
  {
      if (model.Department &gt; 0)
          results = results.Where(x =&gt; x.Department == model.Department);
  
      if (model.RequisitionedBy != null)
          results = results.Where(x =&gt; x.Requisitioned_By.Contains(model.RequisitionedBy));
  
      if (model.Status &gt; 0)
          results = results.Where(x =&gt; x.Status.Contains(model.Status.ToString()));
  
      return results;
  }
  </code></pre>
  
  <p>This code works fine. 
  However, if I add an extra search field to the form, I would also need to add a separate if statement in the controller. 
  With the current approach, the ProcessSearchInput method will contain too many if statements.</p>
  
  <p>Is there a better way to handle a search with multiple fields?</p>