title: C# MVC Search multiple columns in SQL Database table
body: <p>Here is my existing code :</p>
  
  <p>MobileDatas/Index.cshtml</p>
  
  <pre><code>    @using (Html.BeginForm("Index", "MobileDatas", FormMethod.Get))
       {
       &lt;p&gt;
           Manufacturer: @Html.DropDownList("searchGenre", "All")
           Filter By: @Html.TextBox("SearchString") &lt;br /&gt;
           &lt;input type="submit" value="Filter" /&gt;
      &lt;/p&gt;
       }
  </code></pre>
  
  <p>MobileDatasController.cs</p>
  
  <pre><code>    public ActionResult Index(string searchGenre, string searchString)
      {
          string item1 = "Manufacturer";
          string item2 = "Model";
          string item3 = "Network Type";
          var GenreLst = new List&lt;string&gt; { "Manufacturer", "Model", "NetworkType", };
  
          var filterresults = from m in db.MobileDatas
                              select m;
          ViewBag.searchGenre = new SelectList(GenreLst);
  
          if (GenreLst.Contains(Convert.ToString(item1)))
          {
              if (!string.IsNullOrEmpty(searchString))
              {
              filterresults = filterresults.Where(k=&gt;Manufacturer.Contains(searchString));
              }
          }
          else if (GenreLst.Contains(Convert.ToString(item2)))
          {
              if (!string.IsNullOrEmpty(searchString))
              {
                  filterresults = filterresults.Where(x =&gt; x.Model.Contains(searchString));
              }
          }
          else if (GenreLst.Contains(Convert.ToString(item3)))
          {
              if (!string.IsNullOrEmpty(searchString))
              {
                  filterresults = filterresults.Where(v =&gt; v.NetworkType.Contains(searchString));
              }
          }
          return View(filterresults);
      }
  </code></pre>
  
  <p>Database: MobileData</p>
  
  <pre><code>    MobileID Manufacturer Model NetworkType 
      1          Samsung     S4     Orange
      2          Nokia       X1     O2
      3          Sony        Z1     Orange
  </code></pre>
  
  <p>Hi everyone</p>
  
  <p>I'm having some trouble finding/coming up with a solution to my problem. I'm trying to search my table based on the column selected in DropDownList and return the result</p>
  
  <p>for example:  Manufacturer selected + "Sony" typed </p>
  
  <p>the result should just show : 3   Sony Z1  Orange</p>
  
  <p>As it stands my code seams to work for the first if statement if(GenreLst.Contains(Convert.ToString(item1))) </p>
  
  <p>Edit:</p>
  
  <p>found out the above code is breaking as the items are always in GenreList.</p>
  
  <p>How can i return the selected item to compare against item1?</p>