title: How to deal with many possible values to make a query?
body: <p>I'm building an MVC app in which the user will have the possibilities of using a lot of filters to get exactly what he wants.</p>
  
  <p>Here's an overview of those filters based on the controller method:</p>
  
  <pre><code>//
  // GET: /Card/SearchIndex
  public ActionResult SearchIndex(string objName, string objType, string objCostSymbol, string objCost, string powerSymbol,
                                          string powerValue, string ratingSymbol, string ratingValue, string ownerName, string objSet, 
                                          string objRarity, string addCostValue, int? objNumber,
                                          string addCostValue2, string addCostValue3, string addCostValue4, string addCostValue5, string addCostValue6,
                                          bool? blueColor, bool? redColor, bool? yellowColor, bool? purpleColor, bool? greyColor, bool? blackColor,
                                          bool? musicColor, bool? allColor)
          {
               // MORE CODE HERE...
          }
  </code></pre>
  
  <p>I want to know how would be the best way to deal with all these filters, and how could I get a List of objInfo based on the given parameters. Keep in mind that some values may be null. All I've done up to now is load "all" the objInfo I could, then sort them by removing the non-wanted item, which is in my sense "not smart", but I'm new to MVC App and I'm trying to find a better way to do this.</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>Here's the view that generates the data:</p>
  
  <pre><code>@using System.Web.Mvc.Html
  @model PagedList.IPagedList&lt;MvcApp.Models.ObjInfo&gt;
  
  @{
      ViewBag.Title = "SearchIndex";
  }
  
  &lt;h2&gt;Objects Management&lt;/h2&gt;
  
  &lt;p&gt;
      @Html.ActionLink("Create New Obj", "Create")
      @using (Html.BeginForm()){
          &lt;p&gt;
              &lt;label&gt;
                  Obj Colors : Check a box to search for a color.
              &lt;/label&gt;
              All: @Html.CheckBox("allColor", true)&lt;br/&gt;
              Blue: @Html.CheckBox("blueColor", true)
              Red: @Html.CheckBox("redColor", true)
              Yellow: @Html.CheckBox("yellowColor", true) &lt;br/&gt;
              Purple: @Html.CheckBox("purpleColor", true)
              Grey: @Html.CheckBox("greyColor", true)
              Black: @Html.CheckBox("blackColor", true)
              Music: @Html.CheckBox("musicColor", true)
          &lt;/p&gt;
          &lt;p&gt;
              &lt;label&gt;
                  Obj Values: Select a value in the list below.
              &lt;/label&gt;
              Obj Number: &lt;input type="number" min="0" max="9999" name="cardNumber" value="int" style="width: 70px"/&gt;&lt;br/&gt;
              Additional Cost (contains): @Html.DropDownList("addCost", String.Empty) + @Html.DropDownList("addCost2", String.Empty)
              + @Html.DropDownList("addCost3", String.Empty) + @Html.DropDownList("addCost4", String.Empty)
              + @Html.DropDownList("addCost5", String.Empty) + @Html.DropDownList("addCost6", String.Empty)  &lt;br/&gt;
              Cost: @Html.DropDownList("objCostSymbol", "=") @Html.DropDownList("objCost", String.Empty)&lt;br /&gt;
              Power: @Html.DropDownList("powerSymbol", "=") @Html.DropDownList("powerValue", String.Empty)&lt;br/&gt;
              Rating: @Html.DropDownList("ratingSymbol", "=") @Html.DropDownList("ratingValue", String.Empty)&lt;br /&gt;
              &lt;label&gt;
                  Obj Text: Write a name, part of a name, or a word.
              &lt;/label&gt;
              Obj Name: @Html.TextBox("objName") &lt;br/&gt;
              Owner: @Html.TextBox("ownerName") &lt;br /&gt;
              &lt;label&gt;
                  Obj Categories: Select a category in the list below.
              &lt;/label&gt;
              Type: @Html.DropDownList("objType","All") &lt;br/&gt;
              Obj Set: @Html.DropDownList("objSet", "All") &lt;br/&gt;
              Rarity: @Html.DropDownList("objRarity", "All")&lt;br /&gt;
              &lt;div class="float-right"&gt;
                  &lt;input type="submit" value="Filter" name="submitbutton"&gt;
              &lt;/div&gt;
          &lt;/p&gt;
      }
  &lt;/p&gt;
  &lt;span style="color:red; font-size: 1.7em; font-style: italic;"&gt;@ViewData["ErrorMessage"]&lt;/span&gt;
  &lt;table&gt;
      &lt;tr&gt;
          &lt;th&gt;Obj Name&lt;/th&gt;
          &lt;th&gt;Obj Number&lt;/th&gt;
          &lt;th&gt;Obj Color&lt;/th&gt;
          &lt;th&gt;Additional Cost&lt;/th&gt;
          &lt;th&gt;Cost&lt;/th&gt;
          &lt;th&gt;Obj Type&lt;/th&gt;
          &lt;th&gt;@Html.ActionLink("Power", "SearchIndex", new {sortOrder=ViewBag.PowerSortParm})&lt;/th&gt;
          &lt;th&gt;@Html.ActionLink("Rating", "SearchIndex", new {sortOrder=ViewBag.RatingSortParm})&lt;/th&gt;
          &lt;th&gt;Rarity&lt;/th&gt;
          &lt;th&gt;Obj Set Name&lt;/th&gt;
          &lt;th&gt;Owner Name&lt;/th&gt;
          &lt;th&gt;&lt;/th&gt;
      &lt;/tr&gt;
  
      @foreach (var item in Model) {
          &lt;tr&gt;
              &lt;td&gt;
                  @Html.DisplayFor(modelItem =&gt; item.m_ObjName)
              &lt;/td&gt;
              &lt;td&gt;
                  @Html.DisplayFor(modelItem =&gt; item.m_ObjNumber)
              &lt;/td&gt;
              &lt;td&gt;
                  @Html.DisplayFor(modelItem =&gt; item.m_ObjColor)
              &lt;/td&gt;
              &lt;td&gt;
                  @Html.DisplayFor(modelItem =&gt; item.m_ObjAddCost)
              &lt;/td&gt;
              &lt;td&gt;
                  @Html.DisplayFor(modelItem =&gt; item.m_ObjCost)
              &lt;/td&gt;
              &lt;td&gt;
                  @Html.DisplayFor(modelItem =&gt; item.m_ObjType)
              &lt;/td&gt;
              &lt;td&gt;
                  @Html.DisplayFor(modelItem =&gt; item.m_ObjPower)
              &lt;/td&gt;
              &lt;td&gt;
                  @Html.DisplayFor(modelItem =&gt; item.m_ObjRating)
              &lt;/td&gt;
              &lt;td&gt;
                  @Html.DisplayFor(modelItem =&gt; item.m_ObjRarity)
              &lt;/td&gt;
              &lt;td&gt;
                  @Html.DisplayFor(modelItem =&gt; item.m_ObjSet.m_ObjSetName)
              &lt;/td&gt;
              &lt;td&gt;
                  @Html.DisplayFor(modelItem =&gt; item.m_ObjOwner)
              &lt;/td&gt;
              &lt;td&gt;
                  @Html.ActionLink("Edit", "Edit", new { id=item.m_ObjID }) |
                  @Html.ActionLink("Details", "Details", new { id=item.m_ObjID }) |
                  @Html.ActionLink("Delete", "Delete", new { id=item.m_ObjID })
              &lt;/td&gt;
          &lt;/tr&gt;
      }
  &lt;/table&gt;
  
  &lt;div&gt;
      Page @(Model.PageCount &lt; Model.PageNumber ? 0 : Model.PageNumber)
      of @Model.PageCount
  
      @if (Model.HasPreviousPage)
      {
          @Html.ActionLink("&lt;&lt;", "SearchIndex", new {page = 1, sortOrder = ViewBag.CurrentSort})
          @Html.Raw(" ")
          @Html.ActionLink("&lt; Prev", "SearchIndex", new {page = Model.PageNumber - 1, sortOrder = ViewBag.CurrentSort})
      }
      else
      {
          @:&lt;&lt;
          @Html.Raw(" ");
          @:&lt; Prev
      }
  
      @if (Model.HasNextPage)
      {
          @Html.ActionLink("Next &gt;", "SearchIndex", new {page = Model.PageNumber + 1, sortOrder = ViewBag.CurrentSort})
          @Html.Raw(" ")
          @Html.ActionLink("&gt;&gt;", "SearchIndex", new {page = Model.PageCount, sortOrder = ViewBag.CurrentSort})
      }
      else
      {
          @:Next &gt;
          @Html.Raw(" ")
          @:&gt;&gt;
      }
  &lt;/div&gt;
  </code></pre>
  
  <p>Any advice will help me do a better job, thank you.</p>