我命名PagedList了类,看起来像这样:问题与MVC分页表3
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 (this.PageIndex > 0);
}
}
public bool HasNext
{
get
{
return (this.PageIndex + 1 < this.TotalPages);
}
}
public PagedList(IEnumerable<T> source, int pageIndex, int pageSize)
{
this.PageIndex = pageIndex;
this.PageSize = pageSize;
this.TotalCount = source.Count();
this.TotalPages = (int)Math.Ceiling(TotalCount/(double)PageSize);
this.AddRange(source.Skip(this.PageIndex * this.PageSize).Take(this.PageSize));
}
}
在我客户控制器我用它像这样:
public ActionResult Index(int? page)
{
IRepository<UserInfo> profile = ObjectFactory.GetInstance<IRepository<UserInfo>>();
const int pageSize = 25;
IQueryable<UserInfo> profiles = profile.GetAll().OrderBy(x => x.LastName).AsQueryable<UserInfo>();
var pagedCustomers = new PagedList<UserInfo>(profiles, page ?? 0, pageSize);
return View(pagedCustomers);
}
最后在我的Index.cshtml文件中,我设置了我的模型,如下所示:
@model System.Web.Mvc.ViewPage<PagedList<Clusteris.Data.UserInfo>>
而当我去模型。这是一个巨大的列表,与我在Customers控制器中创建的PagedList无关。
任何人有什么想法我做错了什么?
UPDATE:
截图:
你能向我们展示一些模型输出大致的文字吗? – Aaronontheweb
我不确定我是否了解您的请求 – PsychoCoder
“当我去模型时,这是一个巨大的列表,与我在客户控制器中创建的PagedList无关。” - 通过举例的方式解释这意味着什么。 – Aaronontheweb