public PageCustomer CustomerShow(string Name, Nullable <DateTime> time1, Nullable <DateTime> time2, int PageSize = 5, int CurrentPage = 1) { var list = dal.CustomerShow(); if (time1 != null && time2 != null) { list = list.Where(s => s.CreateDate >= time1 && s.CreateDate <= time2).ToList(); } if (Name != null) { list = list.Where(s => s.CustomerName.Contains(Name)).ToList(); } PageCustomer ps = new PageCustomer(); //实例化 ps.TotalCount = list.Count(); //总记录数 if (ps.TotalCount % PageSize == 0) //计算总页数 { ps.TotalPage = ps.TotalCount / PageSize; } else { ps.TotalPage = (ps.TotalCount / PageSize) + 1; } //纠正index页 if (CurrentPage < 1) { CurrentPage = 1; } if (CurrentPage > ps.TotalPage) { CurrentPage = ps.TotalPage; } //赋值index为当前页 ps.CurrentPage = CurrentPage; //linq查询 ps.Customers = list.Skip(PageSize * (CurrentPage - 1)).Take(PageSize).ToList(); return(ps); }