1. Using the pager method, the input parameter returns an HTML string for the navigation bar. The interior of the method is relatively simple.
Ajax-pager.js
/*** pageSize, per page * pageIndex, current page * PageCount total pages * URL Connection Address * pager (1, 5, ' Index ') using the method Example */function pager (Pagesi Ze, pageIndex, PageCount, url) {var intpage = 5; Number shows var intbeginpage = 0;//Start page var intendpage = 0;//End of page var intcrosspage = parseint (INTPAGE/2); Displays the number var strpage = "<div class= ' fr ' ><span class= ' pageinfo ' > <font color= ' #FF0000 ' >" + PageIndex + "/" + PageCount + "</font> page per page <font color= ' #FF0000 ' >" + pageSize + "</font> bar </span>"; if (PageIndex > 1) {strpage = Strpage + "<a class= ' pagenav ' href= '" + URL + "? pageindex=1&pagesize=" + P Agesize + "><span> home </span></a>"; Strpage = strpage + "<a class= ' pagenav ' href= '" + URL + "? pageindex=" + (pageIndex-1) + "&pagesize=" + pageSize + "><span> prev </span></a>"; if (PageCount > Intpage) {//The total number of pages is greater than the number of pages displayed on the page if (PageIndex > Pagecount-intcrosspage) {//Current page ≫ Total pages-3 Intbeginpage = pagecount-intpage + 1; Intendpage = PageCount; } else {if (PageIndex <= intpage-intcrosspage) {intbeginpage = 1; Intendpage = intpage; } else {intbeginpage = Pageindex-intcrosspage; Intendpage = PageIndex + intcrosspage; }}}} else {intbeginpage = 1; Intendpage = PageCount; } if (PageCount > 0) {for (var i = intbeginpage; I <= intendpage; i++) {{if ( i = = PageIndex) {//current page strpage = strpage + "<a class= ' present ' href= ' javascript:void (0); ' > "+ i +" </a> "; } else {strpage = strpage + "<a class= ' pagenav ' href= '" + URL + "? pageindex=" + i + "&pagesize=" + pageSize + "' title= '" + i + "page >" + i + "</a>"; } } } } if (PageIndex < PageCount) {strpage = Strpage + "<a class= ' pagenav ' href= '" + URL + "? pageindex=" + (page Index + 1) + "&pagesize=" + pageSize + "' ><span> next </span></a>"; Strpage = strpage + "<a class= ' pagenav ' href= '" + URL + "? pageindex=" + PageCount + "&pagesize=" + pageSize + " ;<span> End </span></a> "; } return strpage+ "</div>";}
Activity.cshtml
<! DOCTYPE html>View Effects
JS Date Conversion
/* Format Time */date.prototype.format = function (format) {var o = {"m+": This.getmonth () + 1,//month "d+": t His.getdate (),//day "H +": this.gethours (),//hour "m+": This.getminutes (),//minute "s+": this. Getseconds (),//second "q+": Math.floor ((This.getmonth () + 3)/3),//quarter "S": this.getmilliseconds ()/ /millisecond} if (/(y+)/.test (format)) format = Format.replace (regexp.$1, (this.getfullyear () + ""). substr (4-r Egexp.$1.length)); For (var k in O) if (New RegExp ("(" + K + ")"). Test (format)) format = Format.replace (regexp.$1, Regexp.$1.le Ngth = = 1? O[k]: ("XX" + o[k]). substr (("" + o[k]). length); return format;} The string is converted to time function getDate (strdate) {if (strdate! = null) {var date = eval (' New Date (') ' + Strdate.replace (/\d+ ( =-[^-]+$)/, function (a) {return parseint (A, 10)-1;}). Match (/\d+/g) + ') '; return date; } else {return ""; }}//js Time Comparison (YYYY-MM-DD HH:MI:SS) function comparedate (strDate1, StrDate2) {var date1 = new Date (Strdate1.replace (/\-/g, "\ \")); var date2 = new Date (Strdate2.replace (/\-/g, "\ \")); return date1-date2; Console.info (Date1) if (Date1 > Date2) {return 1; } else {return-1; }}//because Firefox is incompatible with Chome//firefox set time plus 1 days function Datenextday (D2) {//slice returns an array var str = D2.slice (5) + "-" + D2.SL Ice (0, 4); var d = new Date (str); var d3 = new Date (D.getfullyear (), D.getmonth ()-1, D.getdate () + 1); var month = Returnmonth (D3.getmonth ()); var month = D3.getmonth (); var day = D3.getdate (); Day = Day < 10? "0" + day:day; var str2 = d3.getfullyear () + "year" + Month + "Month" + Day + "days"; return str2;} Chome set time plus 1 days function Datenextdaychome (D2) {//slice returns an array var str = d2.replace ("month", "/"); var str1 = str.replace ("Day", "" "). substr (5) +"-"+ d2.slice (0, 4); var d = new Date (STR1); var d3 = new Date (D.getfullyear (), D.getmonth ()-1, D.getdate () + 1); var month = Returnmonth (D3.getmonth ()); var month = D3.getmonth (); var day = D3.getdate (); Day = Day < 10? "0" + day:day; var str2 = d3.getfullyear () + "year" + Month + "Month" + Day + "month"; return str2;} Returns the month function Returnmonth (num) {var str = ""; Switch (num) {Case 0:str = "n"; break; Case 1:STR = "02"; Break Case 2:str = "03"; Break Case 3:str = "04"; Break Case 4:STR = "05"; Break Case 5:str = "06"; Break Case 6:str = "07"; Break Case 7:str = "08"; Break Case 8:str = "09"; Break Case 9:STR = "10"; Break Case 10:STR = "11"; Break Case 11:STR = "12"; Break } return str;} Data.rows[i]. Bengintime.getdatebyjson ("Yyyy-mm-dd") String.prototype.getDateByJson = function (format) {var jsondate = This.replace ("/date (", ""). Replace (")/", ""); if (Jsondate.indexof ("+") > 0) {jsondate = jsondate.substring (0, JsondatE.indexof ("+")); } else if (Jsondate.indexof ("-") > 0) {jsondate = jsondate.substring (0, Jsondate.indexof ("-")); } return new Date (parseint (jsondate)). Format (format);
Reference: http://www.cnblogs.com/xiaoafei1991/p/4246662.html Sharp JS front page pagination of jquery
MVC-20. Front-page Ajax paging