title: MVCContrib grid: Paging and Sorting execute the Controller's HttpGet method. Why?
body: <p>I have a page where I have a dropdownlist which controls a grid. For this grid I use MVCContrib.
  When I change the value of my dropdownlist, the Controller's HttpPost method is called and this works fine.
  However when I page or sort the grid, the HttpGet method is called, always. Why? This is surely not how it should be?
  Now in the code below I take this into account and I have something that works. But the code is aweful, especially the use of Session. There must be a better way of dealing with this?
  The controller code is;</p>
  
  <pre><code>[HttpGet]
  [Authorize(Roles = "Administrator, AdminAccounts, ManagerAccounts")]
  public ActionResult ListHistory(GridSortOptions sort, int? page)
  {
      EmployeeListViewModel employees = null;
      if (sort.Column == null &amp;&amp; page.HasValue == false)
      {
          employees = new EmployeeListViewModel(EmployeeExtended.GetAllFormerEmployees(), 1);
          Session["EmployeeListViewModel"] = employees;
      }
      else
      {
          employees = Session["EmployeeListViewModel"] as EmployeeListViewModel;
      }
  
      if (sort.Column != null)
      {
          employees.EmployeeList = employees.EmployeeList.OrderBy(sort.Column, sort.Direction);
      }
      int pageLength = Convert.ToInt32(ConfigurationManager.AppSettings["EmployeeListPageLength"].ToString());
      employees.EmployeeList = employees.EmployeeList.AsPagination(page ?? 1, pageLength);
      ViewData["sort"] = new GridSortOptions();
      return View(employees);
  }
  
  [HttpPost]
  [Authorize(Roles = "Administrator, AdminAccounts, ManagerAccounts")]
  public ActionResult ListHistory(GridSortOptions sort, EmployeeListViewModel elvm, int? page)
  {
      IEnumerable&lt;EmployeeExtended&gt; employees = null;
  
      switch (elvm.OptionsId)
      {
          case 1: employees = EmployeeExtended.GetAllFormerEmployees();
              break;
          case 2: employees = EmployeeExtended.GetAllOnNoticeEmployees();
              break;
          case 3: employees = EmployeeExtended.GetAllCurrentEmployees();
              break;
      }
  
      if (sort.Column != null)
      {
          employees = employees.OrderBy(sort.Column, sort.Direction);
      }
      int pageLength = Convert.ToInt32(ConfigurationManager.AppSettings["EmployeeListPageLength"].ToString());
      employees = employees.AsPagination(page ?? 1, pageLength);
      ViewData["sort"] = sort;
      EmployeeListViewModel elvm1 = new EmployeeListViewModel(employees, elvm.OptionsId);
      Session["EmployeeListViewModel"] = elvm1;
      return View(elvm1);
  }
  </code></pre>
  
  <p>The view code is;</p>
  
  <pre><code>&lt;% using (Html.BeginForm())
     {%&gt;
     &lt;%: Html.AntiForgeryToken() %&gt;
  &lt;fieldset&gt;
      &lt;legend&gt;List of Employees&lt;/legend&gt;
      &lt;% if (ViewData["LastPersonMessage"] != null &amp;&amp; ViewData["LastPersonMessage"].ToString().Length &gt; 0)
          { %&gt;
          &lt;p class="error"&gt;
              At &lt;% Response.Write(DateTime.Now.ToString("T")); %&gt;. &lt;%: ViewData["LastPersonMessage"]%&gt;.
          &lt;/p&gt;
      &lt;%} %&gt;
      &lt;p&gt;Click on history to view the history of an employee.&lt;/p&gt;
      &lt;p&gt;Select which employees you want to see: 
          &lt;%:Html.DropDownListFor(model =&gt; model.OptionsId, Model.Options, new { onchange = "this.form.submit();" })%&gt;
      &lt;/p&gt;
      &lt;%: Html.Grid(Model.EmployeeList).Columns(column =&gt;
      {
          column.For(model =&gt; Html.ActionLink("History", "ShowHistory", new { employeeId = model.EmployeeId })).Named("").DoNotEncode();
          column.For(model =&gt; model.Forename); 
          column.For(model =&gt; model.Surname);
          column.For(model =&gt; model.DivisionName);
          column.For(model =&gt; model.DepartmentName);
          column.For(model =&gt; model.StartDate).Format("{0:d}");
          column.For(model =&gt; model.EndDate).Format("{0:d}");
      }).Sort((GridSortOptions)ViewData["sort"])%&gt;
      &lt;p&gt;&lt;%= Html.Pager((IPagination)Model.EmployeeList)%&gt;&lt;/p&gt;
      &lt;p&gt;&lt;/p&gt;
  &lt;/fieldset&gt;
  &lt;% } %&gt;
  </code></pre>