ASP.NET MVC 分页问题
在使用Ajax.Pager进行分页的时候需要注意一下几个方面:
1、一定要引入jquery.unobtrusive-ajax.min.js这个js;
2、一定要在页面中使用注册分页器,注册方法:@{Html.RegisterMvcPagerScriptResource();};
具体的使用方法示例:
1 <div class="row" style="position: relative; left: 30%"> 2 <div class="col-md-8" style="width: auto"> 3 @{ 4 PagerConfig pagerConfig = new PagerConfig("pageIndex", "pageIndexBox", "goToBtn"); 5 PagerOptions options = pagerConfig.GetPagerOption(); 6 } 7 @Ajax.Pager(Model, options).AjaxOptions(a => a.SetUpdateTargetId("articles").SetHttpMethod("Post").SetDataFormId("searchView")) 8 </div> 9 <div class="col-md-4"> 10 <div class="input-group" style="width: 120px; margin: 20px 0"> 11 <input type="text" id="pageIndexBox" class="form-control" /> 12 <span class="input-group-btn"><button class="btn btn-primary" id="goToBtn">跳转</button></span> 13 </div> 14 </div> 15 </div>
其中Model是IpagedList对象,获取PagerOptions的方法如下:
1 /// <summary> 2 /// 翻页配置项 3 /// </summary> 4 /// <returns></returns> 5 public PagerOptions GetPagerOption() 6 { 7 PagerOptions options = new PagerOptions 8 { 9 AutoHide = false, 10 FirstPageText = "首页", 11 LastPageText = "尾页", 12 NextPageText = "下一页", 13 PrevPageText = "上一页", 14 PageIndexParameterName = this._pageIndexParaName, 15 ContainerTagName = "ul", 16 CssClass = "pagination", 17 CurrentPagerItemTemplate = "<li class=\"active\"><a href=\"#\">{0}</a></li>", 18 DisabledPagerItemTemplate = "<li class=\"disabled\"><a>{0}</a></li>", 19 PagerItemTemplate = "<li>{0}</li>", 20 PageIndexBoxId = this._pageIndexBoxId, 21 GoToButtonId = this._goToButtonId, 22 NumericPagerItemCount = 5 23 }; 24 25 return options; 26 }