Mvcpager How to use pagination

Source: Internet
Author: User

 Public ActionResult adminuserlist (Userlistmodel model)        {            var pagedlist = _userservice.searchadminusers (model. PageIndex, model. PageSize, model. Name, model. IsActive);             New Pagedlist<userlistitem> (mapper.map<list<userlistitem>>(pagedlist), PagedList.PageIndex, Pagedlist.pagesize, Pagedlist.totalcount);             return View (model);        }
Controller
 Public classUserlistitem { PublicGuid Id {Get;Set; } [Display (Name="Login Account")]         Public stringLoginId {Get;Set; } [Display (Name="name")]         Public stringName {Get;Set; } [Display (Name="e-Mail")]         Public stringEmail {Get;Set; } [Display (Name="Phone number")]         Public stringPhone {Get;Set; } [Display (Name="Activate")]         Public BOOLIsActive {Get;Set; } [Display (Name="Registration Date")]         PublicDateTime Registerdate {Get;Set; } /// <summary>        ///Membership Level/// </summary>[Display (Name ="Membership Level")]         PublicViplevel Viplevel {Get;Set; } }  Public classUserlistmodel:basequerymodel { PublicUserlistmodel () {IsActive=true; }        #regionUser PublicIpagedlist<userlistitem> Items {Get;Set; } [Display (Name="Login Account")]         Public stringLoginId {Get;Set; } [Display (Name="name")]         Public stringName {Get;Set; } [Display (Name="Phone number")]         Public stringPhone {Get;Set; } [Display (Name="Activate")]         Public BOOLIsActive {Get;Set; } }
Model
1   Public Abstract classBasequerymodel2     {3          PublicBasequerymodel ()4         {5PageIndex =0;6PageSize = -;7         }8 9          Public intPageIndex {Get;Set; }Ten          Public intPageSize {Get;Set; } One  A          Publicroutevaluedictionary toparms () -         { -RouteValueDictionary dic =Newroutevaluedictionary (); the              This. GetType (). GetProperties (). Where (x =x.propertytype.isprimitive -||X.propertytype.isvaluetype -|| (Nullable.getunderlyingtype (x.propertytype)! =NULL&& (Nullable.getunderlyingtype (X.propertytype). Isvaluetype | |Nullable.getunderlyingtype (X.propertytype). isprimitive)) -|| X.propertytype = =typeof(string)). ToList (). ForEach (x = dic. ADD (X.name, X.getvalue ( This))); +             returndic; -         } +}
Basequerymodel
 PublicIpagedlist<user> Searchusers (intPageIndex,intPageSize,stringNameBOOLisActive) {            varquery = This. _userrep.table; if(!string. Isnullorwhitespace (name)) {Query= Query. Where (x = X.name = =name); } Query= Query. Where (x = x.isactive = =isActive); Query= Query. Where (x = X.isdelete = =false); Query= Query. Where (x = x.isactive = = IsActive && X.usertype = =Usertype.customer); Query= Query. OrderByDescending (x = x.registerdate). (x =x.name); return NewPagedlist<user>(query, PageIndex, pageSize); }
Method

Referenced Mvcpager,dll address: http://www.webdiyer.com/aspnetpager/relatedlinks/

A part of the code is the framework of packaging good, we look at the idea is good.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.