title: Paged List in MVC
body: <p>To perform paging I have followed this method
  <a href="http://www.asp.net/mvc/tutorials/getting-started-with-ef-using-mvc/sorting-filtering-and-paging-with-the-entity-framework-in-an-asp-net-mvc-application" rel="nofollow">http://www.asp.net/mvc/tutorials/getting-started-with-ef-using-mvc/sorting-filtering-and-paging-with-the-entity-framework-in-an-asp-net-mvc-application</a></p>
  
  <p>Now what I am trying to do is change the page size by choosing a value from drop down</p>
  
  <pre><code> Page Sige :
             @{
               IList&lt;SelectListItem&gt; pageSizeList = new List&lt;SelectListItem&gt;();
               pageSizeList.Add(new SelectListItem { Text = "5", Value = "5", Selected = true });
               pageSizeList.Add(new SelectListItem { Text = "10", Value = "10" });
               pageSizeList.Add(new SelectListItem { Text = "15", Value = "15" });
               pageSizeList.Add(new SelectListItem { Text = "20", Value = "20" });
               pageSizeList.Add(new SelectListItem { Text = "25", Value = "25" });
               }
               @Html.DropDownListFor(per =&gt; per.PageSize, pageSizeList, new
               {
                  @onchange = "location.href='/AdminSearchResult/AdminSearchResult?pageSizeInput=' + this.value;"
               })
  </code></pre>
  
  <p>After choosing the value from dropdown I made few changes to my sorting and paging action links. I added a bool parameter isPageSort, as follows</p>
  
  <pre><code>@Html.ActionLink("  Previous Page  ", "AdminSearchResult", new { page = Model.PageNumber - 1, sortOrder = ViewBag.CurrentSort, currentFilter = ViewBag.CurrentFilter, isSortPage = "true"  }) -------For paging
  
  @Html.ActionLink("Last Name", "AdminSearchResult", new { sortOrder = ViewBag.LastNameSortParm, currentFilter = ViewBag.CurrentFilter, isSortPage = "true" }) ------For sorting
  </code></pre>
  
  <p>based on this bool parameter I save the current page size in session and retrieve to maintain the page size in my controller.</p>
  
  <pre><code>[HttpGet]
      public ActionResult AdminSearchResult(string sortOrder, int? page, int pageSizeInput = 0,  bool isSortPage = false)
      {
          int pageSize = 5;         
          int pageNumber = 1;
          if (page != null)
              pageNumber = Convert.ToInt32(page);
  
  
          if (!isSortPage)
          {
              if (pageSizeInput != 0)
                  pageSize = pageSizeInput;
              Session["pageSize"] = pageSize;
          }
          else
              pageSize = (int)Session["pageSize"];
  
          Session["sortOrder"] = sortOrder;
          Session["pageNumber"] = pageNumber;
  
          var userList = SortResult(sortOrder);
  
          return View(userList.ToPagedList(pageNumber, pageSize));
      } 
  </code></pre>
  
  <p>I want to know is there a more efficient way to do the same.</p>