In fact, there is nothing, that is, record it and share it with you.
As a project of Asp.net MVC 2.0, the paging function must be used. I searched the internet a few times. By chance, I found the mvcpager paging control, and I felt like it very much. (PS: The buddy who writes this control is a person with hearing impairment. I admire it here, depending on the Early Recovery)
The usage method is as follows:
You can simply query the. topagedlist (pageindex, pagesize) in your own LINQ query set, which is really convenient. Put it in the project immediately. This is a tragedy. The topagedlist (***) method cannot be found. Cause Analysis: topagedlist should be an extension method. I have not used LINQ in my project. querying all lists returned by the Basic ado.net reader <t> set. I feel the problem is definitely here. There are no extension methods such as list <t> set, that is, ienumerable <t>. I searched the mvcpager source code online, haha. You can see it in codeplex. Thanks to cnblogs, csdn, msdn, And If You Are the One. Open Source: I am open source. Haha.
The next step is to download the source code, which is very small. Open the project and you will see a class: pagelinqextensions. cs. It must be literally understood. Open it and it looks like this:
Code
Public Static Class Pagelinqextensions
{
Public Static Pagedlist < T > Topagedlist < T >
(
This Iqueryable < T > Allitems,
Int Pageindex,
Int Pagesize
)
{
If (Pageindex < 1 )
Pageindex = 1 ;
VaR itemindex = (Pageindex - 1 ) * Pagesize;
VaR pageofitems = Allitems. Skip (itemindex). Take (pagesize );
VaR totalitemcount = Allitems. Count ();
Return New Pagedlist < T > (Pageofitems, pageindex, pagesize, totalitemcount );
}
}
Refer to the type parameter in the topagedlist <t> extension method. iqueryable <t> is correct, so list <t> conversion is not supported. As a result, no matter the class name rules are not standardized, add the followingCode:
Code
Public Static Pagedlist < T > Topagedlist < T > ( This Ienumerable < T > Allitems, Int Pageindex, Int Pagesize)
{
Pageindex = Pageindex < 1 ? 1 : Pageindex;
VaR itemindex = (Pageindex - 1 ) * Pagesize;
VaR pageofitems = Allitems. Skip (itemindex). Take (pagesize );
VaR totalitemcount = Allitems. Count ();
Return New Pagedlist < T > (Pageofitems, pageindex, pagesize, totalitemcount );
}
An extension method is overloaded, and the type parameter is ienumerable <t>. This overload is used to support topagedlist (***) Paging conversion of list <t>. So far. Project test is available.
PS: although the current popularity of LINQ and Entity Framework is getting more and more popular, the former ado.net is still widely used. So you have to consider it. (If there is any error, you are welcome to testify. If you find the fault, you will be immediately dismounted)