• MVCPager分页使用方法


     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.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
    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/

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

  • 相关阅读:
    汇编(一)续
    汇编(一)
    Ubuntu 安装配置Dosbox
    Linux系统安装Dos系统(虚拟机里装)
    .bundle文件如何安装
    Linux(Fedora)系统下配制8086汇编环境
    Linux常用命令
    linux下安装nginx
    缓存雪崩、缓存穿透、缓存击穿是什么?如何解决?
    Maven 实战
  • 原文地址:https://www.cnblogs.com/baiyunchen/p/3920684.html
Copyright © 2020-2023  润新知