码迷,mamicode.com
首页 > Web开发 > 详细

MVCPager分页使用方法

时间:2014-08-18 23:27:13      阅读:410      评论:0      收藏:0      [点我收藏+]

标签:des   cPage   style   blog   http   color   使用   os   

bubuko.com,布布扣
 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
bubuko.com,布布扣
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
bubuko.com,布布扣
 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.IsPrimitive
16                  || x.PropertyType.IsValueType
17                  || (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
bubuko.com,布布扣
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/

有一部分代码是框架封装好的,大家看思路就好。

MVCPager分页使用方法,布布扣,bubuko.com

MVCPager分页使用方法

标签:des   cPage   style   blog   http   color   使用   os   

原文地址:http://www.cnblogs.com/baiyunchen/p/3920684.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!