title: Search data in table using ajax in ASP.net MVC
body: <p>I want to display data in a table based on the search criteria in a textbox. I have implemented it without using Ajax but do not know how to call controller method using jquery and update table data. Please try to solve my problem. Thanks...</p>
  
  <p>Index.cshtml</p>
  
  <pre><code>@model IEnumerable&lt;MvcApplication4.Models.tbl_product&gt;
  @{
      Layout = null;
  }
  
      &lt;!DOCTYPE html&gt;
  &lt;html&gt;
  &lt;head&gt;
      &lt;script src="@Url.Content("~/Scripts/jquery-1.5.1.js")" type="text/javascript"&gt;&lt;/script&gt;
      &lt;title&gt;Index&lt;/title&gt;
      &lt;script type="text/javascript"&gt;
          $(document).ready(function () {
              $('#Button1').click(function () {
                  alert("button clicked");
                  $.ajax({
                      type: 'POST',
                      contentType: "application/json; charset=utf-8",
                      url: 'Home/Index',
                      data: "{'searchString':'" + document.getElementById('searchString').value + "'}",
                      async: false,
                      Success: function (response) {
                          alert("Success");
  
                             window.location.reload();
                      },
                      error: function () { alert("error"); }
                  });
  
              });
          });
      &lt;/script&gt;
  &lt;/head&gt;
  &lt;body&gt;
      @*  @using (@Html.BeginForm("Index", "Home"))
      {*@
      @Html.TextBox("searchString");
      &lt;input type="button" value="filter" id="Button1" /&gt;
      @* }*@
      &lt;table id="showData"&gt;
          @{Html.RenderPartial("SearchList");}
      &lt;/table&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>SearchList.cshtml(Partial View)</p>
  
  <pre><code>@foreach (var item in Model)
  { 
  &lt;tr&gt;
  &lt;td&gt;@item.ProductName&lt;/td&gt;
  &lt;td&gt;@item.ProductId&lt;/td&gt;
  &lt;td&gt;@item.ProductDesc&lt;/td&gt;
  &lt;/tr&gt;
  }
  </code></pre>
  
  <p>HomeController.cs</p>
  
  <pre><code> public class HomeController : Controller
      {
          //
          // GET: /Home/
          ProductEntities dbentity = new ProductEntities();
          public ActionResult Index()
          {
              return View(dbentity.tbl_product.ToList());
          }
  
          [HttpPost]
          public ActionResult Index(string searchString)
          {
              var query = dbentity.tbl_product.Where(c =&gt; c.ProductName.Contains(searchString));
              return View(query.ToList());
          }
  
     }
  </code></pre>