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.