ltect
ltect

Reputation:

Paging in asp.net mvc c#

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);
    }

Upvotes: 0

Views: 297

Answers (1)

Haacked
Haacked

Reputation: 59011

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.

Upvotes: 1

Related Questions