title: Table Sorting/Filtering with ASP.NET MVC 5 and Entity Framework
body: <p>I have been following the Contoso Tutorial from Microsoft and have my Scaffolding built pulling data tables from an offsite SQL Server. I have attempted inserting similar code to what is in the tutorial and it creates links, but does not sort or filter as it should. It only refreshes the page. Something seems to be working because when I hit the links for sorting, the URL parameters change, but the table does not change.</p>
  
  <p>Here is the controller for the sort/filter Actions</p>
  
  <pre><code>public ActionResult Index(string sortOrder, string searchString)
      {
          ViewBag.NameSortParm = String.IsNullOrEmpty(sortOrder) ? "Name_desc" 
  : "";
          ViewBag.DateSortParm = sortOrder == "Date" ? "Date_desc" : "Date";
          var schedules = from s in db.schedules
                         select s;
          if (!String.IsNullOrEmpty(searchString))
          {
              schedules = schedules.Where(s =&gt;s.designation.Contains(searchString)
                                     || s.Function.Contains(searchString));
          }
          switch (sortOrder)
          {
              case "Name_desc":
                  schedules = schedules.OrderByDescending(s =&gt; s.designation);
                  break;
              case "Date":
                  schedules = schedules.OrderBy(s =&gt; s.promise_ship_date);
                  break;
              case "Date_desc":
                  schedules = schedules.OrderByDescending(s =&gt; s.promise_ship_date);
                  break;
              default:
                  schedules = schedules.OrderBy(s =&gt; s.promise_ship_date);
                  break;
          }
          return View(db.schedules.ToList());
      }
  </code></pre>
  
  <p>Here is my Index Page</p>
  
  <pre><code>@model IEnumerable&lt;WebApplication1.Models.schedule&gt;
  
  @{
  ViewBag.Title = "Index";
  Layout = "~/Views/Shared/_Layout.cshtml";
  }
  
  &lt;h2&gt;Index&lt;/h2&gt;
  
  &lt;p&gt;
  @Html.ActionLink("Create New", "Create")
  &lt;/p&gt;
  
  @using (Html.BeginForm())
  {
  &lt;p&gt;
      Find by designation or function: @Html.TextBox("searchString")
      &lt;input type="submit" value="Search"/&gt;
  &lt;/p&gt;
  }
  
  &lt;table class="table"&gt;
  &lt;tr&gt;
      &lt;th&gt;
          @Html.ActionLink("Designation", "Index", new { sortOrder = ViewBag.NameSortParm })
      &lt;/th&gt;
      &lt;th&gt;
          @Html.DisplayNameFor(model =&gt; model.Function)
      &lt;/th&gt;
      &lt;th&gt;
          @Html.DisplayNameFor(model =&gt; model.lv_mv)
      &lt;/th&gt;
      &lt;th&gt;
          @Html.ActionLink("Promise Ship Date", "Index", new { sortOrder = ViewBag.DateSortParm })
  </code></pre>
  
  <p>Any help would be greatly appreciated.</p>