public ViewResult Index(int? pageIndex ,string search) { int pageInd = pageIndex.HasValue ? pageIndex.Value : 1; ViewBag.PageCount = (int)Math.Ceiling(result.Count() / 20.0); return View(result.OrderBy(t => t.PID).Skip((pageInd - 1) * 20).Take(20)); }
视图(页面调用):
@using (Html.BeginForm())
{
根据性别得到查询结果
性别: @Html.TextBox("sex")
<input type="submit" value="查询" />
@Html.Action("PageIndexKey", "PageIndex", new { pageCount = ViewBag.PageCount, currentPage = ViewBag.CurrentPage })
}
Example:
//数据,一个list的集合 List<string> s = new List<string>(); s.Add("张军"); ViewBag.PageCount = (int)Math.Ceiling(s.Count() / 20.0); return View(s.Skip((pageInd - 1) * 20).Take(20)); @Html.Action("PageIndex", "PageIndex", new { action = "", controller = "", pageCount = ViewBag.PageCount, currentPage = ViewBag.CurrentPage })