title: Problems sorting a list of data in ASP.net MVC3
body: <p>I am trying to implemeny the sorting functionality thats shown in the Entity Framework tutorials on the the Asp.net MVC Site, here</p>
  
  <p><a href="http://www.asp.net/entity-framework/tutorials/sorting-filtering-and-paging-with-the-entity-framework-in-an-asp-net-mvc-application" rel="nofollow">http://www.asp.net/entity-framework/tutorials/sorting-filtering-and-paging-with-the-entity-framework-in-an-asp-net-mvc-application</a></p>
  
  <p>For some reason although i can see that the correct query strings are being added to the url, the data is not sorting,</p>
  
  <p>I have the following switch statement in my controller to allow me to sort the data by the customer name or the primary contact name</p>
  
  <pre><code>//Returns a list of all the customers to be displayed on the (Master edit page)
      //- TODO - Implement Paging Functionality
      public ViewResult Index(string sortOrder)
      {
          ViewBag.CustomerNameSortParm = String.IsNullOrEmpty(sortOrder) ? "CustomerName desc" : "";
          ViewBag.PrimaryContactNameSortParm = sortOrder == "PrimaryContactName" ? "PrimaryContactName desc" : "PrimaryContactName";
          var cust = repository.Customers;
  
          switch (sortOrder)
          {
              case "CustomerName desc":
                  cust = repository.Customers.OrderByDescending(s =&gt; s.CustomerName);
                  break;
              case "PrimaryContactName":
                  cust = repository.Customers.OrderBy(s =&gt; s.PrimaryContactName);
                  break;
              case "PrimaryContactName desc":
                  cust = repository.Customers.OrderByDescending(s =&gt; s.PrimaryContactName);
                  break;
              default:
                  cust = repository.Customers.OrderBy(s =&gt; s.CustomerName);
                  break;
          }
  
          return View(repository.Customers.ToList());
      }
  </code></pre>
  
  <p>Then in the view i have links created for each of the coumn headings</p>
  
  <pre><code>&lt;th class="header"&gt;
         @Html.ActionLink("Customer Name", "Index", new { sortOrder=ViewBag.CustomerNameSortParm })
      &lt;/th&gt;
      &lt;th class="header"&gt;
        @Html.ActionLink("Contact Name", "Index", new { sortOrder=ViewBag.PrimaryContactNameSortParm })
      &lt;/th&gt;
  </code></pre>
  
  <p>When i click on the links i can see the query string values in the URL like</p>
  
  <p><a href="http://localhost:58783/Admin/Index?sortOrder=PrimaryContactName" rel="nofollow">http://localhost:58783/Admin/Index?sortOrder=PrimaryContactName</a></p>
  
  <p>But the data is not being sorted, has anyone experienced similar issues, or know where i am going wrong? for some reason the comments at the bottom of the Entity Framework tutorial are not being displayed so i cant see if anyone else has has this issue.</p>
  
  <p>The only difference i can see with my code is that in the tutorial a LINQ query is used in the controller, where i am using the repository and returning my customers from the repository which returns an IQueryable list of customers.</p>
  
  <p>Any advice is appreciated.</p>
  
  <p>Liam.</p>