问题在PagedList MVC分页 [英] Issue with pagination in PagedList MVC
问题描述
我使用MVC的 PagedList 办理的分页在我的项目。一切正常,只是在我的控制器精我必须初始化 PAGENUMBER 是1(默认页码)参数。问题是蓝色的启动第1页上的按钮,仍然存在无论哪个页面按钮链接您点击。此外,这种按钮也缺少ActionLink的。
我整合的最后一件事我的搜索是分页,你可以在控制器code看到的。
公共PartialViewResult List_Items(串关键词,诠释?页)
{
VAR newlists从s在db.TrMs =
排序依据s.S1
选择S; INT PAGENUMBER =(第53页1);
INT的pageSize = 10;
VAR数据= newlists.Where(F => f.S1.ToString()包含(关键字)及&安培; f.S100 == VT).ToPagedList(PAGENUMBER,pageSize的);
返回PartialView(数据);
}
下面是生成的 HTML为PagedList 在我的查看
< DIV CLASS =分页容器>
< UL类=分页>
<李班=主动>
&所述a取代1所述; / A>
< /李>
<立GT;
<数据阿贾克斯=真正的数据Ajax的方法=GET数据AJAX模式=替换数据AJAX更新=#SearchResult中的href =/ TRM / Search_Items关键字=放?;放大器;页= 2→2&下; / A>
< /李>
<立GT;
<数据阿贾克斯=真正的数据Ajax的方法=GET数据AJAX模式=替换数据AJAX更新=#SearchResult中的href =/ TRM / Search_Items关键字=放?;放大器;页= 3→3&下; / A>
< /李>
<立GT;
<数据阿贾克斯=真正的数据Ajax的方法=GET数据AJAX模式=替换数据AJAX更新=#SearchResult中的href =/ TRM / Search_Items关键字=放?;放大器;页= 4→4&下; / A>
< /李>
<李班=PagedList-skipToNext>
<数据阿贾克斯=真正的数据Ajax的方法=GET数据AJAX模式=替换数据AJAX更新=#SearchResult中的href =/ TRM / Search_Items关键字=放?;放大器;页面= 2的rel =下一步>»< / A>
< /李>
< / UL>
< / DIV>
这里是我如何使用分页帮手。
页@;:中(Model.PageCount&LT Model.PageNumber 0?Model.PageNumber)@ Model.PageCount
@ Html.PagedListPager(型号,页= GT; Url.Action(List_Items,TRM,新的{关键词=,页}),PagedListRenderOptions.EnableUnobtrusiveAjaxReplacing(新AjaxOptions(){列举HTTPMethod =GET,UpdateTargetId =信息搜索结果}))
您分页控件是在信息搜索结果容器的最有可能的外面。当你点击一个页面上,你要替换的表,但不分页控件。移动你的分页控件您的信息搜索结果容器内!
希望这有助于。
I am using MVC PagedList to handle pagination in my project. Everything works fine except that in my controller I have to initialize pageNumber parameter with "1" (Default page number). The problem is the blue activated button on page 1 that remains there no matter which page button link you click. Moreover this button is also missing the actionLink.
One last thing I am integrating my search with pagination as you can see in the controller code.
public PartialViewResult List_Items(string keyword, int? page)
{
var newlists = from s in db.TrMs
orderby s.S1
select s;
int pageNumber = (page ?? 1);
int pageSize = 10;
var data = newlists.Where(f => f.S1.ToString().Contains(keyword) && f.S100 == vt).ToPagedList(pageNumber, pageSize);
return PartialView(data);
}
Here is the generated Html for PagedList in my view
<div class="pagination-container">
<ul class="pagination">
<li class="active">
<a>1</a>
</li>
<li>
<a data-ajax="true" data-ajax-method="GET" data-ajax-mode="replace" data-ajax-update="#searchResult" href="/TrM/Search_Items?keyword=&page=2">2</a>
</li>
<li>
<a data-ajax="true" data-ajax-method="GET" data-ajax-mode="replace" data-ajax-update="#searchResult" href="/TrM/Search_Items?keyword=&page=3">3</a>
</li>
<li>
<a data-ajax="true" data-ajax-method="GET" data-ajax-mode="replace" data-ajax-update="#searchResult" href="/TrM/Search_Items?keyword=&page=4">4</a>
</li>
<li class="PagedList-skipToNext">
<a data-ajax="true" data-ajax-method="GET" data-ajax-mode="replace" data-ajax-update="#searchResult" href="/TrM/Search_Items?keyword=&page=2" rel="next">»</a>
</li>
</ul>
</div>
Here is how I am using the pagination helper.
Page @(Model.PageCount < Model.PageNumber ? 0 : Model.PageNumber) of @Model.PageCount
@Html.PagedListPager(Model, page => Url.Action("List_Items", "TrM", new {keyword="", page }), PagedListRenderOptions.EnableUnobtrusiveAjaxReplacing(new AjaxOptions() { HttpMethod = "GET", UpdateTargetId = "searchResult" }))
Your paging controls are most likely outside of the searchResult container. When you click on a page you're replacing the table but not the paging controls. Move your paging controls inside of your searchResult container!
Hope this helps.
这篇关于问题在PagedList MVC分页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!