title: how to search a list of products using controller by Name or Id
body: <p>I want to load a list of products in view according to search. If user enters name or id the product should be shown. I tried but I'm only able to do with only one of these.</p>
  
  <p>this is how i tried.</p>
  
  <p>Controller</p>
  
  <pre><code>public class SearchController : Controller
      {
  
          private storeEntities db = new storeEntities();
  
          public ActionResult Find()
              {
              var det = (from d in db.products
                         select d).ToList();
              return View(det);
  
              }
          [HttpPost]
          public ActionResult Find(int pid)
          {
              var det = (from d in db.products
                         where d.id == pid
                         select d).ToList();
  
              return View(det);
          }
      }
  </code></pre>
  
  <p>View</p>
  
  <pre><code>@model IEnumerable&lt;SearchAppMvc.Models.product&gt;
  
  @{
      ViewBag.Title = "Find";
  }
  
  &lt;h2&gt;Find&lt;/h2&gt;
  &lt;div&gt;
  @Html.Partial("_SearchPartial")
  &lt;/div&gt;
  
  &lt;p&gt;
      @Html.ActionLink("Create New", "Create")
  &lt;/p&gt;
  &lt;table&gt;
      &lt;tr&gt;
          &lt;th&gt;
              category
          &lt;/th&gt;
          &lt;th&gt;
              productName
          &lt;/th&gt;
          &lt;th&gt;
              price
          &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.category)
          &lt;/td&gt;
          &lt;td&gt;
              @Html.DisplayFor(modelItem =&gt; item.productName)
          &lt;/td&gt;
          &lt;td&gt;
              @Html.DisplayFor(modelItem =&gt; item.price)
          &lt;/td&gt;
          &lt;td&gt;
              @Html.ActionLink("Edit", "Edit", new { id=item.id }) |
              @Html.ActionLink("Details", "Details", new { id=item.id }) |
              @Html.ActionLink("Delete", "Delete", new { id=item.id })
          &lt;/td&gt;
      &lt;/tr&gt;
  }
  </code></pre>
  
  <p></p>
  
  <p>partial view</p>
  
  <pre><code>@using (Html.BeginForm( new RouteValueDictionary {{"controller","Search"},{"action","Find"},{"id","pid"}}))
  {
      @*@Html.Editor("name")*@
  
      @Html.TextBox("pid")
  
      &lt;input type="submit" value="search"/&gt;                        
  }
  </code></pre>
  
  <p>and model is done using entity frame work</p>