在我的项目中,我有一个名为UserInfo的表(将在本文中缩写),如下所示:
public class UserInfo()
{
public virtual string FirstName{get;set;}
public virtual string LastName{get;set;}
public virtual string Email{get;set;}
}
我正在填充一个PagedList,这是一个帮助启用我的数据分页的类。在控制器中我有这个代码:
public ActionResult Index(int? page)
{
IRepository<Clusteris.Data.UserInfo> profile = ObjectFactory.GetInstance<IRepository<Clusteris.Data.UserInfo>>();
const int pageSize = 10;
IQueryable<Clusteris.Data.UserInfo> profiles = profile.GetAll().OrderBy(x => x.LastName).AsQueryable();
var pagedCustomers = new PagedList<Clusteris.Data.UserInfo>(profiles, page ?? 0, pageSize);
return View(pagedCustomers);
}
这是PagedList:
public class PagedList<T> : List<T>
{
public int PageIndex { get; private set; }
public int PageSize { get; private set; }
public int TotalCount { get; private set; }
public int TotalPages { get; private set; }
public bool HasPrevious { get { return (PageIndex > 0); } }
public bool HasNext { get { return (PageIndex + 1 < TotalPages); } }
public PagedList(IQueryable<T> source, int pageIndex, int pageSize)
{
PageIndex = pageIndex;
PageSize = pageSize;
TotalCount = source.Count();
TotalPages = (int)Math.Ceiling(TotalCount / (double)PageSize);
this.AddRange(source.Skip(PageIndex * PageSize).Take(PageSize));
}
}
除了一个铃声之外,它的工作正常,它只返回电子邮件值,而不是第一个&amp;姓氏(虽然我知道他们有价值)。知道为什么只返回1个值?