ASP.NET MVC 4+ T.JPager使用
一、同步Link模式
var pagecount = TCalcPager.CalcPageCount(count, pageSize); var page = new TBuilderLinkPager() { Tag = "a", PageCount = pagecount, PageSize = pageSize, PageIndex = pageIndex, Path = "/home/list/", CurrentPageClassName = "page_curr", NextPageName = ">", UpPageName = "<" }; page.Params.Add(UserId); page.BuilderHTML(); //将页码,总页数和查询的当前页的集合传递到视图上 ViewBag.PagerHTML = page.PagerHTML; ViewBag.PageIndex = pageIndex; ViewBag.PageCount = pagecount;
/Home/List/UserId/PageIndex
备注: PageIndex会默认附加到最后一个参数
二、异步事件模式
var pagecount = TCalcPager.CalcPageCount(count, pageSize); var page = new TBuilderPager { Tag = "a", PageCount = pagecount, PageSize = pageSize, PageIndex = pageindex, Path = "/Search/List", NextPageClickName = "nextPager", UpPageClickName = "upPager", CurrentPageClassName = "page_curr", PageClickName = "pager", NextPageName = "下一页", UpPageName = "上一页" }; page.BuilderHTML(); //将页码,总页数和查询的当前页的集合传递到视图上 ViewBag.PagerHTML = page.PagerHTML; ViewBag.PageIndex = pageindex; ViewBag.PageCount = pagecount;
1.单个视图页的js,事件命名必须是 pager(href, pageindex){}
//通用分页click function pager(href, pageindex) { var _begintime = $("#g_begintime_hidden").val(); var _endtime = $("#g_endtime_hidden").val(); var _tiaojian = $("#g_tiaojian_hidden").val(); g_loading(); $("#gonghuolist").load(href, { pageindex: pageindex, beginTime: _begintime, endTime: _endtime, tiaojian: _tiaojian, state: $("#shenhezhuangtai_hidden").val() }, function () { g_closeloading(); }); }
三、JPager MVC扩展类
public static class TJPagerExtentions { /// <summary> /// 异步标准版 /// </summary> /// <param name="help"></param> /// <param name="param"></param> /// <returns></returns> public static IHtmlString Pager(this HtmlHelper help, TBuilderPager param) { var page = new TBuilderPager { Tag = param.Tag, PageCount = param.PageCount, PageSize = param.PageSize, PageIndex = param.PageIndex, Path = param.Path, NextPageClickName = param.NextPageClickName, UpPageClickName = param.UpPageClickName, CurrentPageClassName = param.CurrentPageClassName, PageClickName = param.PageClickName, NextPageName = param.NextPageName, DefaultClassName = param.DefaultClassName, UpPageName = param.UpPageName, HomePageClassName = param.HomePageClassName, LastPageClassName = param.LastPageClassName }; page.BuilderHTML(); return help.Raw(page.PagerHTML); } /// <summary> /// 异步带首页尾页版 /// </summary> /// <param name="help"></param> /// <param name="param"></param> /// <returns></returns> public static IHtmlString PagerWithFL(this HtmlHelper help, TBuilderPager param) { var page = new TBuilderPager { Tag = param.Tag, PageCount = param.PageCount, PageSize = param.PageSize, PageIndex = param.PageIndex, Path = param.Path, NextPageClickName = param.NextPageClickName, UpPageClickName = param.UpPageClickName, CurrentPageClassName = param.CurrentPageClassName, PageClickName = param.PageClickName, NextPageName = param.NextPageName, UpPageName = param.UpPageName, DefaultClassName = param.DefaultClassName, HomeAndLastPageClickName = param.HomeAndLastPageClickName, HomePageClassName = param.HomePageClassName, LastPageClassName = param.LastPageClassName }; page.BuilderHTMLWithFL(); return help.Raw(page.PagerHTML); } /// <summary> /// 异步极小的,不带总页数+首页尾页的版 /// </summary> /// <param name="help"></param> /// <param name="param"></param> /// <returns></returns> public static IHtmlString PagerWithNormal(this HtmlHelper help, TBuilderPager param) { var page = new TBuilderPager { Tag = param.Tag, PageCount = param.PageCount, PageSize = param.PageSize, PageIndex = param.PageIndex, Path = param.Path, NextPageClickName = param.NextPageClickName, UpPageClickName = param.UpPageClickName, CurrentPageClassName = param.CurrentPageClassName, PageClickName = param.PageClickName, NextPageName = param.NextPageName, UpPageName = param.UpPageName, DefaultClassName = param.DefaultClassName, }; page.BuilderHTMLWithBuilderWithNormal(); return help.Raw(page.PagerHTML); } /// <summary> /// 同步标准版 /// </summary> /// <param name="help"></param> /// <param name="param"></param> /// <returns></returns> public static IHtmlString LinkPage(this HtmlHelper help, TBuilderLinkPager param) { var page = new TBuilderLinkPager { Tag = param.Tag, PageCount = param.PageCount, PageSize = param.PageSize, PageIndex = param.PageIndex, Path = param.Path, CurrentPageClassName = param.CurrentPageClassName, NextPageName = param.NextPageName, UpPageName = param.UpPageName, DefaultClassName = param.DefaultClassName, HomePageClassName = param.HomePageClassName, LastPageClassName = param.LastPageClassName }; page.BuilderHTML(); return help.Raw(page.PagerHTML); } /// <summary> /// 同步带首页尾页版本 /// </summary> /// <param name="help"></param> /// <param name="param"></param> /// <returns></returns> public static IHtmlString LinkPageWithFL(this HtmlHelper help, TBuilderLinkPager param) { var page = new TBuilderLinkPager { Tag = param.Tag, PageCount = param.PageCount, PageSize = param.PageSize, PageIndex = param.PageIndex, Path = param.Path, CurrentPageClassName = param.CurrentPageClassName, NextPageName = param.NextPageName, UpPageName = param.UpPageName, DefaultClassName = param.DefaultClassName, HomePageClassName = param.HomePageClassName, LastPageClassName = param.LastPageClassName }; page.BuilderHTMLWithFL(); return help.Raw(page.PagerHTML); } }