tags:

views:

92

answers:

1
public ActionResult Index(int? page, FormCollection collection)
{
   query = GetClients(collection);
   var pagedView= new PaginatedList<Clients>(query, page ?? 0, pageSize);
   return View(pagedView);
}

The above works if i am on page 1. When i click on page 2 link it fails for the reason that 'collection param is null and GetClients returns all the records rather then what I am search against.

The form collection has the following text box:First Name, Company Name, Zip

Is there a way to keep the query returned in session and then during each paging event, check the session object and if it has the IQueryable object then extract from it else call GetClients(collection)

Update 1: My updated code

public ActionResult Index(int? page, FormCollection collection)
    {
       ClientSearch clientSearch = new ClientSearch();
       this.UpdateModel(clientSearch, new[] { "FName",Lane",Zip","Phone"});
       query = GetClients(clientSearch);
       var pagedView= new PaginatedList<Clients>(query, page ?? 0, pageSize);
       return View(pagedView);
    }
+1  A: 

That's because your link is issuing a GET request and the form data is not being submitted to page 2. You could either have your page 2 link issue a form post using JavaScript (not recommended) or simply pass in the form data into that link so they show up in the query string.

Haacked
Hacked: if by bad design my search page has 20 elements that they can search against, building the querystring would cause issue as if memory serves me right, the query string has a character limit. Are Session objects not recommend in asp.net mvc?