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

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

  • 相关阅读:
    Spring Boot 返回 XML 数据,一分钟搞定!
    Spring Cloud Alibaba Sentinel 整合 Feign 的设计实现
    周末去面试,进去 5 分钟就出来了…
    Spring Boot 返回 JSON 数据,一分钟搞定!
    Java 11 已发布,String 还能这样玩!
    Hashtable 为什么不叫 HashTable?
    Java 中初始化 List 集合的 6 种方式!
    HashMap 和 Hashtable 的 6 个区别,最后一个没几个人知道!
    毕业不到一年,绩效打了个D!
    poj 3111 K Best (二分搜索之最大化平均值之01分数规划)
  • 原文地址:https://www.cnblogs.com/baiyunchen/p/3920684.html
Copyright © 2020-2023  润新知