本页面初始url的hash值中包含MvcPager页索引参数(#id=3),因此打开页面时MvcPager会自动跳转到第三页并加载显示第三页数据。
- Url路由分页
- Ajax分页
- Ajax搜索分页
- 外观样式
- 分页数据相关
- Javascrip API
- AjaxPager 类
- AjaxHelper.Pager 扩展方法
- HtmlPager 类
- HtmlHelper.Pager 扩展方法
- IPagedList 接口
- IPagedList<T> 接口
- MvcAjaxOptions 类
- MvcAjaxOptionsBuilder 类
- PagedList<T> 类
- PageLinqExtensions 类
-
PagerOptions 类
- ActionName属性
- AlwaysShowFirstLastPageNumber属性
- AutoHide属性
- ContainerTagName属性
- ControllerName属性
- CssClass属性
- CurrentPageNumberFormatString属性
- CurrentPagerItemTemplate属性
- DisabledPagerItemTemplate属性
- FirstPageRouteName属性
- FirstPageText属性
- GoToButtonId属性
- HidePagerItems属性
- HorizontalAlign属性
- HtmlAttributes属性
- Id属性
- InvalidPageIndexErrorMessage属性
- LastPageText属性
- MaximumPageIndexItems属性
- MaximumPageNumber属性
- MorePagerItemTemplate属性
- MorePageText属性
- NavigationPagerItemsPosition属性
- NavigationPagerItemTemplate属性
- NextPageText属性
- NumericPagerItemCount属性
- NumericPagerItemTemplate属性
- OnPageIndexError属性
- PageIndexBoxId属性
- PageIndexOutOfRangeErrorMessage属性
- PageIndexParameterName属性
- PageNumberFormatString属性
- PagerItemTemplate属性
- PrevPageText属性
- RouteName属性
- RouteValues属性
- ShowDisabledPagerItems属性
- ShowFirstLast属性
- ShowMorePagerItems属性
- ShowNumericPagerItems属性
- ShowPrevNext属性
- PagerItemsPosition 枚举
- PagerOptionsBuilder 类
- ScriptResourceExtensions 类
- Javascript API
- AjaxPager.cs
- AjaxPagerTest.cs
- DataLoaderBuilder.cs
- DisplayNameExtensions.cs
- HtmlPager.cs
- HtmlPagerTest.cs
- IPagedList.cs
- MvcAjaxOptions.cs
- MvcAjaxOptionsBuilder.cs
- MvcPager.js
- PagedList.cs
- PagedListTest.cs
- PageLinqExtensions.cs
- PagerBuilder.cs
- PagerExtensions.cs
- PagerItem.cs
- PagerItemsPosition.cs
- PagerOptions.cs
- PagerOptionsBuilder.cs
- ScriptResourceExtensions.cs
- TestHelper.cs
MvcPager 分页示例 — Ajax初始化数据
该示例演示Ajax分页模式下,MvcPager根据当前url中的页索引hash值在页面加载时,通过Ajax自动跳转并加载当前页数据的功能。
View:
@model PagedList<article> <div id="articles"> @Html.Partial("_ArticleList",Model) </div> @section Scripts{@{Html.RegisterMvcPagerScriptResource();}}
_ArticleList.cshtml:
@model PagedList<article> <div class="text-center"> @Ajax.Pager(Model, new PagerOptions { PageIndexParameterName = "id", ContainerTagName = "ul", CssClass = "pagination", CurrentPagerItemTemplate = "<li class=\"active\"><a href=\"#\">{0}</a></li>", DisabledPagerItemTemplate = "<li class=\"disabled\"><a>{0}</a></li>", PagerItemTemplate = "<li>{0}</li>" }).AjaxOptions(a => a.SetUpdateTargetId("articles")) </div> @{ Html.RenderPartial("_ArticleTable"); } <div class="text-center"> @Ajax.Pager(Model, new PagerOptions { PageIndexParameterName = "id", ContainerTagName = "ul", CssClass = "pagination", CurrentPagerItemTemplate = "<li class=\"active\"><a href=\"#\">{0}</a></li>", DisabledPagerItemTemplate = "<li class=\"disabled\"><a>{0}</a></li>", PagerItemTemplate = "<li>{0}</li>" }).AjaxOptions(a => a.SetUpdateTargetId("articles")) </div>
_ArticleTable.cshtml:
@model PagedList<Article> <table class="table table-bordered table-striped"> <tr> <th class="nowrap">序号</th> <th> @Html.DisplayNameFor(model => model.Title) </th> <th> @Html.DisplayNameFor(model => model.PubDate) </th> <th> @Html.DisplayNameFor(model => model.Author) </th> <th> @Html.DisplayNameFor(model => model.Source) </th> </tr> @{ int i = 0;} @foreach (var item in Model) { <tr> <td>@(Model.StartItemIndex + i++)</td> <td> @Html.DisplayFor(modelItem => item.Title) </td> <td> @Html.DisplayFor(modelItem => item.PubDate) </td> <td> @Html.DisplayFor(modelItem => item.Author) </td> <td> @Html.DisplayFor(modelItem => item.Source) </td> </tr> } </table>
Model:
public class Article { [Display(Name="文章编号")] public int ID { get; set; } [Display(Name="文章标题")] [MaxLength(200)] public string Title { get; set; } [Display(Name = "文章内容")] public string Content { get; set; } [Display(Name = "发布日期")] public DateTime PubDate { get; set; } [Display(Name = "作者")] [MaxLength(20)] public string Author { get; set; } [Display(Name = "文章来源")] [MaxLength(20)] public string Source { get; set; } }
Controller:
public ActionResult AjaxInitData(int id = 1) { using (var db = new DataContext()) { var model = db.Articles.OrderByDescending(a => a.PubDate).ToPagedList(id, 5); if (Request.IsAjaxRequest()) return PartialView("_ArticleList", model); return View(model); } }