MVCPager分頁使用方法

來源:互聯網
上載者:User

標籤:des   cPage   style   blog   http   color   使用   os   

 public ActionResult AdminUserList(UserListModel model)        {            var pagedList = _userService.SearchAdminUsers(model.PageIndex, model.PageSize, model.Name, model.IsActive);            model.Items = new PagedList<UserListItem>(Mapper.Map<List<UserListItem>>(pagedList), pagedList.PageIndex, pagedList.PageSize, pagedList.TotalCount);            return View(model);        }
Controller
public class UserListItem    {        public Guid Id { get; set; }        [Display(Name = "登入帳號")]        public string LoginId { get; set; }        [Display(Name = "姓名")]        public string Name { get; set; }        [Display(Name = "電子郵箱")]        public string Email { get; set; }        [Display(Name = "手機號")]        public string Phone { get; set; }        [Display(Name = "啟用")]        public bool IsActive { get; set; }        [Display(Name = "註冊日期")]        public DateTime RegisterDate { get; set; }        /// <summary>        /// 會員層級        /// </summary>        [Display(Name = "會員層級")]        public VIPLevel VIPLevel { get; set; }    } public class UserListModel : BaseQueryModel    {        public UserListModel()        {            IsActive = true;        }        #region User        public IPagedList<UserListItem> Items { get; set; }        [Display(Name = "登入帳號")]        public string LoginId { get; set; }        [Display(Name = "姓名")]        public string Name { get; set; }        [Display(Name = "手機號")]        public string Phone { get; set; }        [Display(Name = "啟用")]        public bool IsActive { get; set; }    }
Model
 1  public abstract class BaseQueryModel 2     { 3         public BaseQueryModel() 4         { 5             PageIndex = 0; 6             PageSize = 20; 7         } 8  9         public int PageIndex { get; set; }10         public int PageSize { get; set; }11 12         public RouteValueDictionary ToParms()13         {14             RouteValueDictionary dic = new RouteValueDictionary();15             this.GetType().GetProperties().Where(x => x.PropertyType.IsPrimitive16                  || x.PropertyType.IsValueType17                  || (Nullable.GetUnderlyingType(x.PropertyType) != null && (Nullable.GetUnderlyingType(x.PropertyType).IsValueType || Nullable.GetUnderlyingType(x.PropertyType).IsPrimitive))18                  || x.PropertyType == typeof(string)).ToList().ForEach(x => dic.Add(x.Name, x.GetValue(this)));19             return dic;20         }21     }
BaseQueryModel
public IPagedList<User> SearchUsers(int pageIndex, int pageSize, string name, bool isActive)        {            var query = 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).OrderBy(x => x.Name);            return new PagedList<User>(query, pageIndex, pageSize);        }
Method

引用了MVCPager,DLL地址:http://www.webdiyer.com/aspnetpager/relatedlinks/

有一部分代碼是架構封裝好的,大家看思路就好。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.