title: Sorting fields ascending and descending with single link
body: <p>So I have a MVC app with a table and when the header is clicked I would like it to switch between sorting in ascending or descending fashion depending how many times it is clicked.</p>
  
  <p>Currently I can only sort descending or ascending I don't know how to implement both. <code>userName</code> is just a variable I'm getting from another controller when a user logs in and I'm using a switch because I plan on having multiple headers that can be sortable.</p>
  
  <h1>View</h1>
  
  <pre><code>&lt;table&gt;
      &lt;tr&gt;
          &lt;th&gt;
              &lt;a href="@Url.Action("Dispatch", "Calls", new { userName = Session["UserName"], new { sortOrder = "Name_desc" })"&gt;Name&lt;/a&gt;
          &lt;/th&gt;
      &lt;/tr&gt;
  &lt;/table&gt;
  </code></pre>
  
  <h1>Controller</h1>
  
  <pre><code>public ActionResult Index(string userName, string sortOrder)
  {
      string userName = Session["UserName"].ToString();
  
      var model = from t in db.Users
                  where t.UserName == userName
                  select t;
  
      switch(sortOrder)
      {
          case "Name_desc":
              model = model.OrderByDescending(t =&gt; t.UserName);
              break;
      }
  }
  </code></pre>