Search code examples
asp.net-mvcdata-paging

Paging the data in .net MVC, and need to pass data between different Views


.net MVC 2.0 question:

The main problem is I want to paging my data in Arraylist and show them in different pages in the View. (I want to paging data on client side because on my server side, data source stored in hash table, I can not do paging in database) Here is a View called "Search", which user can input keyword and click "submit" button and submit the form to Action:

     [AcceptVerbs(HttpVerbs.Post)]
    public ActionResult SearchKey(FormCollection forms)
{
//Deal with the searching keywords and return the new result list
ViewData["result"]=result_list;
return View("Search",Model); 
//I can not use return RedirectToAction("Search",new{id=page_num}) 
//which can not return the ViewData
}


public ActionResult Search()
{
ArrayList result_list = new ArrayList();
ViewData["result"]=result_list;
//I will also need to pass a Model to the view
return View(Model);
}

When I view my result, the url is:/Controller/SearchKey
So till here, everything is fine, I can get correct searching result, but I want to paging the result.Then I need to pass page number to the view, but the url:/Controller/SearchKey/page_num is not validate, if I type /Controller/Search/page_num, there is empty result (the result is returned from "SearchKey" action)

So my question is, for this situation, if I want to do client-side paging, what should I do? Thanks


Solution

  • If you want to paginate client side try to use an HTML table with a jQuery plungin such as DataTables or jqGrid.

    In the basic MVC MasterPage you already have jQuery loaded.