title: Sorting a HTML table using Search Keyword?
body: <p>I have my table displaying, searching, and sorting correctly. But when I search a keyword and display the records in my table and click the column header to sort, the search results gets cleared and I always get brought back to the original page instead of sorting the results of my search. I don't understand why is that happening? Any help would be greatly appreciated. Thank You</p>
  
  <p>Controller:</p>
  
  <pre><code>public ActionResult ViewInventory(string owners, string keyword, string sortOrder)
          {
              ViewBag.OwnerSort = sortOrder == "owner_asce" ? "owner_desc" : "owner_asce";
  
              var records = from s in db.Assets select s;
              switch (sortOrder)
              {
                  case "owner_asce":
                      records = records.OrderBy(s =&gt; s.InventoryOwner);
                  break;
  
                  case "owner_desc":
                      records = records.OrderByDescending(s =&gt; s.InventoryOwner);
                  break;
              }
             return View(records.ToList());
  }
  </code></pre>
  
  <p>View:</p>
  
  <pre><code>@model IEnumerable&lt;CTS_Inventory.Models.Asset&gt;
  
  @{
      ViewBag.Title = "View Inventory";
  }
  
  &lt;h2&gt;View Inventory&lt;/h2&gt;
  
  
  @using (Html.BeginForm())
  {
      &lt;p&gt;
  
          Keyword Search: @Html.TextBox("keyword") 
  
          &lt;input type="submit" value="Search" /&gt;
      &lt;/p&gt;
  
      &lt;table class="table" border="1"&gt;
          &lt;tr&gt;
              &lt;th&gt;
                  @Html.ActionLink("owners","ViewInventory", new { sortOrder = ViewBag.OwnerSort})
              &lt;/th&gt;
          &lt;/tr&gt;
  
          @foreach (var item in Model)
          {
              &lt;tr&gt;
                  &lt;td&gt;
                      @Html.DisplayFor(modelItem =&gt; item.InventoryOwner)
                  &lt;/td&gt;
              &lt;/tr&gt;
          }
      &lt;/table&gt;
  }
  </code></pre>