点击页数无反应?
private static readonly int PAGE_SIZE = 2;
private int GetPageCount(int recordCount)
{
int pageCount = recordCount / PAGE_SIZE;
if (recordCount % PAGE_SIZE != 0)
{
pageCount += 1;
}
return pageCount;
}
private List<ProjectsModel> GetPagedDataSource(IQueryable<ProjectsModel> projects,int pageIndex, int recordCount)
{
var pageCount = GetPageCount(recordCount);
if (pageIndex >= pageCount && pageCount >= 1)
{
pageIndex = pageCount - 1;
}
return projects.OrderBy(m => m.Id).Skip(pageIndex * PAGE_SIZE).Take(PAGE_SIZE).ToList();
}
public ActionResult Index()
{
var projects = db.ProjectsModels as IQueryable<ProjectsModel>;
var recordCount = projects.Count();
var pageCount = GetPageCount(recordCount);
ViewBag.PageIndex = 0;
ViewBag.PageCount = pageCount;
//ViewBag.MajorList = GetMajorList();
return View(GetPagedDataSource(projects, 0, recordCount));
}
<div id="pagebar">
@for (var i = 0; i < ViewBag.PageCount; i++)
{
if (i == ViewBag.PageIndex)
{
<span class="currentpagenumber">@(i + 1)</span>
}
else
{
<a class="pagenumber" href="javascript:;">@(i + 1)</a>
}
}
</div>
?
- 分页的model查询:Paging with ASP.NET MVC – Martijn Boland (taiga.nl);
- 已实现。分页显示,但是不能使用IEnumerable的DisplayNameFor功能获得表头:ASP.NET MVC5 PagedList分页示例 (bbsmax.com);
- 采用GridView分页:在ASP.NET MVC5中实现具有服务器端过滤、排序和分页的GridView-阿里云开发者社区 (aliyun.com);
|