在使用Ajax.Pager進(jìn)行分頁的時候需要注意一下幾個方面:
1、一定要引入jquery.unobtrusive-ajax.min.js這個js;
2、一定要在頁面中使用注冊分頁器,注冊方法:@{Html.RegisterMvcPagerScriptResource();};
具體的使用方法示例:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
< div class = "row" style = "position: relative; left: 30%" > < div class = "col-md-8" style = "width: auto" > @{ PagerConfig pagerConfig = new PagerConfig("pageIndex", "pageIndexBox", "goToBtn"); PagerOptions options = pagerConfig.GetPagerOption(); } @Ajax.Pager(Model, options).AjaxOptions(a => a.SetUpdateTargetId("articles").SetHttpMethod("Post").SetDataFormId("searchView")) </ div > < div class = "col-md-4" > < div class = "input-group" style = "width: 120px; margin: 20px 0" > < input type = "text" id = "pageIndexBox" class = "form-control" /> < span class = "input-group-btn" >< button class = "btn btn-primary" id = "goToBtn" >跳轉(zhuǎn)</ button ></ span > </ div > </ div > </ div > |
其中Model是IpagedList對象,獲取PagerOptions的方法如下:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
/// <summary> /// 翻頁配置項 /// </summary> /// <returns></returns> public PagerOptions GetPagerOption() { PagerOptions options = new PagerOptions { AutoHide = false , FirstPageText = "首頁" , LastPageText = "尾頁" , NextPageText = "下一頁" , PrevPageText = "上一頁" , PageIndexParameterName = this ._pageIndexParaName, 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>" , PageIndexBoxId = this ._pageIndexBoxId, GoToButtonId = this ._goToButtonId, NumericPagerItemCount = 5 }; return options; } |
目前所知,該控件不支持顯示記錄總數(shù)及總頁數(shù)。
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持服務(wù)器之家。