views:

781

answers:

4

Hi, is there some elegant way, ideally with jquery plugin like pager 1 or pager 2 how to implement paging with asp.net mvc? I am trying to go over partial views, but so far unsucessfully. Where should I store the loaded grid data? And how to respond on the page selection with just a partial refresh?

Thanks in advance.

+3  A: 

The MVC Contrib Grid comes with paging functionality. Might be worth a look.

redsquare
A: 

You wouldn't store the loaded data. MVC allows you to keep the view stateless, so the call back to the controller for the next page needs to include the page number being requested. Then you just return the rows required. You could also use AJAX for that.

Lazarus
+4  A: 

Try this article out, looks pretty handy - he uses a custom Html extension method. Also, check this SO question.

Kieron
I used this to handle the paging which was not in a Grid. I can to customize the code, but it works really well.
Martin
+1  A: 

I suggest checking out ScottGu's NerdDinner as he shows how to make a pager with ASP.NET MVC there.

One way you can do it is to transmit the result range via the URL, i.e.

http://domain.com/Products/List/0-10

...could show 10 products starting at 0. If you had many search fields, another way would be to have a contoller with a List action returning JSON, XML or an HTML table that you could call using an AJAX GET.

But I highly suggest checking out NerdDinner, as he has an example of how to do this.

cdmckay
You will also see this explained in the Wrox MVC book (where they use NerdDinner as their sample) -- you can download and read the first chapter (which is nearly one-third of the entire book!) online for free. (Purchasing the book is more ideal, of course!)
Funka