title: ASP.NET MVC Search Form with Pagination
body: <p>Im at a loss for words, as I must be missing something. Just finished ASP.NET MVC 1.0 (WROX) and Im trying to implement a view that performs a simple search then renders the results in a table. I would then like to be able to page thru the results.</p>
  
  <p>So I have a search action from ListingsController, takes some values from FormCollection and filters the results accordingly:</p>
  
  <pre><code>        //
      //POST: /Listings/Search
      //      /Listings/Page/2
      [AcceptVerbs(HttpVerbs.Post)]
      public ActionResult Search(FormCollection collection,int? page)
      {
          var listings = listingRepository.GetListings();
  
          //filter
          if (collection["TypeOfHouse"] != null)
          {
              string[] typeList = collection["TypeOfHouse"].Split(',');
  
              foreach (string type in typeList)
              {
                  listings = from l in listings
                             where l.TypeOfHouse == type
                             select l;
              }
          }
  
          //display the first page of results
          int pageSize = 25;
          var paginatedListings = new PriviledgeV1.Helpers.PaginatedList&lt;Listing&gt;(listings, 0, pageSize);
  
  
  
          return View("Results", paginatedListings);
      }
  </code></pre>
  
  <p>Initially the Results view will be rendered with the first 25 records for page 1. Then I have a Results action that handles the "pagination":</p>
  
  <pre><code>    public ActionResult Results(int? page)
      {
          int pageSize = 25;
          var listings = listingRepository.GetListings();
          var paginatedListings = new PriviledgeV1.Helpers.PaginatedList&lt;Listing&gt;(listings, page ?? 0, pageSize);
  
          return View(listings);
      }
  </code></pre>
  
  <p>Trouble is because I no longer have the FormCollection, I cannot properly filter results. So if I tried to move from say page 1 to page 2 using /Listings/Results?page=2, the results action would fire and it would return ALL results instead of the filtered result set from the Search action.</p>
  
  <p>I'm really confused as to what to do here, and as to why there are no blogs/tutorials explaining this, which normally flags me that I am missing something.</p>
  
  <p>Thanks!</p>