由于之前写了一个局部刷新的分页,为了自己以后工作方便所以再上传一个通用的分页,基于bootstrap的分页,引用和上次写的局部刷新一样,在这里就不写了
js代码 在页面加载的时候执行
var options = { bootstrapMajorVersion: 3,//版本 currentPage: @Convert.ToInt64(Model.PageNumber) ,//当前页数 numberOfPages: 10,//设置显示的页码数 totalPages: @Convert.ToInt64(Model.PageCount) ,//总页数 itemTexts: function (type, page, current) { switch (type) { case "first": return "首页"; case "prev": return "上一页"; case "next": return "下一页"; case "last": return "末页"; case "page": return page; } }, pageUrl: function (type, page, current) { return "/Comment/CarReply?pageIndex=" + page; } }; element.bootstrapPaginator(options);
html
<div> <ul id="page"></ul> </div>
Controller代码(需要返回分页类型)
[AuthorizationCodeAttribute] [Description("评论信息")] [HttpPost] public ActionResult Comment(int id,int? page) { #region 评论列表 var dal = new CarCommentOperator(); int pageIndex = page ?? 1;//当前页 if (!string.IsNullOrEmpty(Request.QueryString["pageindex"])) { if (!int.TryParse(Request.QueryString["pageindex"], out pageIndex)) { pageIndex = 1; } } const int pageSize = 2; long totalCount; long totalPageCount; IEnumerable<CarComment> list = dal.GetList(pageIndex, pageSize, out totalPageCount, out totalCount, "CarId=" + id); var commentIPagedList = new StaticPagedList<CarComment>(list, pageIndex, pageSize, Convert.ToInt32(totalCount)); #endregion return View(commentIPagedList); }
基于bootstrap的分页
时间: 2024-10-03 12:18:18