In my previous work, I used a lot of pagination, but it has been not solid, so it is not easy to use. This is a pagination with partial refresh. I tried a lot. I wanted to use mvcPager for partial refresh, but considering the cost is too high, I gave up. Let's summarize the pagination based on bootstrap first, so that it can be convenient for me to use in the future
Open source address https://github.com/lyonlai/bootstrap-paginator
Quote first
Jquery
bootstrap.min.js
bootstrap-paginator.min.js
Controller code
[AuthorizationCodeAttribute][Description("Comment Information")][HttpPost]public ActionResult Comment(int id, int? page){#region Comment List var dal = new CarCommentOperator();int pageIndex = page ?? 1;//Current page 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//Convert to Json format var strResult = "{/"pageCount/":" + commentIPagedList.PageCount + ",/"CurrentPage/":" + commentIPagedList.PageNumber + ",/"list/":" + JsonConvert.SerializeObject(list) + "}"; return Json(strResult, JsonRequestBehavior.AllowGet);}js code
<script type="text/javascript">$(document).ready(function() { var carId = 1;$.ajax({url: "/car/Comment",datatype:'json',type: "Post",data: "id=" + carId,success: function(data) { if (data!=null) { $.each(eval("(" + data + ")").list, function(index, item) { //Transtraight the returned json $("#list").append('<table>');$("#list").append('<tr>');$("#list").append('<td>Commenter</td>');$("#list").append('<td>'+item.UserProfileId+'</td>');$("#list").append('</tr> ');$("#list").append('<tr>');$("#list").append('<td>content</td>');$("#list").append('<td>'+item.Content+'</td>');$("#list").append('</tr>');$("#list").append('</table>'); }); //Add select option $("#commentList").append('<div id="pager"><ul id="page"></ul></div>');var element = $("#page"); var pageCount = eval("(" + data + ")").pageCount; //Get pageCount in the returned Json data (convert the returned data to object type)var currentPage = eval("(" + data + ")").CurrentPage; //Go to the returned Json data CurrentPagevar options = { bootstrapMajorVersion: 3, //Version currentPage: currentPage, //Current page numberOfPages: 5, //Set the displayed page number totalPages:pageCount, //Total page number itemTexts: function(type, page, current) {switch (type) {case "first":return "Homepage";case "prev":return "Previous page";case "next":return "Next page";case "last":return "Last page";case "page":return page;}//}//pageUrl: function(type, page, current) {// return "/car/Details?page=" + page;},//Click event onPageClicked: function(event, originalEvent, type, page) { $.ajax({url: "/car/Comment?id="+carId,type: "Post",data:"page="+page,success: function(data1) {if (data1!=null) {$("#list").html("");$.each(eval("(" + data1 + ")").list, function (index, item) { //Transfer the returned json $("#list").append('<table style="border: 1px solid #00ced1;width: 300px">');$("#list").append('<tr>');$("#list").append('<td>Commenter</td>');$("#list").append('<td>'+item.UserProfileId+'</td>');$("#list").append('</tr>');$("#list").append('<tr>');$("#list").append('<td>');$("#list").append('<td>'+item.Content+'</td>');$("#list").append('</tr>');$("#list").append('</table>'); }); }}});}};element.bootstrapPaginator(options);}}});});The above is the page refresh based on BootStrap introduced by the editor to you. I hope it will be helpful to you. If you have any questions, please leave me a message and the editor will reply to you in time. Thank you very much for your support to Wulin.com website!