Will_paginate for ASP.NET MVC

2019-06-07 09:51发布

问题:

I was run across issue to paging my list object in asp.net mvc where my object is simply load by LINQ-to-SQL.

Is it some kinds of will_paginates command?

in rails, i can do like

Users.paginate(:all, :page => 1, :page_size => 20)

回答1:

Check out - http://pagedlist.codeplex.com/

Will create an extension method ToPagedList which can be used like so:

 using PagedList;

 var firstPage = list.ToPagedList(0, 20); // first page, page size = 20

 Console.WriteLine("Is first page? {0}", firstPage.IsFirstPage); // true
 Console.WriteLine("Is last page? {0}", firstPage.IsLastPage); // false
 Console.WriteLine("First value on page? {0}", firstPage[0]); // 1
 Console.WriteLine();


回答2:

In Linq this would be

Users.Skip(pageSize*page).Take(pageSize)

This would assume zero based counting.



回答3:

MVCContrib has a very flexible and easy to use pager