//根据条件查找数据 list = Stdqj.FindAll(where, "ID desc", "", (pageindex - 1) * 15, 15); // 根据list查找的条件,查找list的总数(count) ViewBag.total = Stdqj.FindCount(where); //在传递参数中传递pageindex //获取当前pageindex的值 ViewBag.pageindex = pageindex; } return View(list);
<div id="pager"> <a href="javascript:;" οnclick="goPage(1)">首页</a> //pageindex如果大于1:pageindex=3(当前页=3)则存在第1页第2页,允许点击上一页 @if (ViewBag.pageindex > 1) { <a href="javascript:;" οnclick="goPage(@(ViewBag.pageindex - 1))">上一页</a> } else { <a href="javascript:;" class="noContent">上一页</a> } //如果数量大于当前页pageindex*15则允许点击下一页/末页 @if (ViewBag.total > ViewBag.pageindex * 15) { <a href="javascript:;" οnclick="goPage(@(ViewBag.pageindex + 1))" class="noContent">下一页</a> //向上取整 <a href="javascript:;" οnclick="goPage(@(Math.Ceiling(Convert.ToDouble(ViewBag.total)/15)))" class="noContent">末页</a> } else { <a href="javascript:;" class="noContent">下一页</a> <a href="javascript:;" class="noContent">末页</a> } </div> <script type="text/javascript"> goPage = (function (page) { var s = window.location.href; if (/pageindex=/.test(s)) s = s.replace(/pageindex=[0-9]*/, "pageindex=" + page); else s = s + "&pageindex=" + page; if (!/\?/.test(s)) s = s.replace("&", "?"); window.location.href = s; }); </script>