PagedList MVC 中的分页问题

Issue with pagination in PagedList MVC

我在我的项目中使用 MVC PagedList 来处理 分页。一切正常,除了在我的 controller 中我必须用 "1" 初始化 pageNumber 参数(默认页码)。问题是第 1 页上的蓝色激活按钮无论您单击哪个页面 按钮 link 都会保留在那里。此外,这个 按钮 也缺少 actionLink。

最后一件事,我正在将我的 searchpagination 集成,如您在控制器代码中所见。

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);
}

这是在我的 view

中为 PagedList 生成的 Html
<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=&amp;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=&amp;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=&amp;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=&amp;page=2" rel="next">»</a>
        </li>
    </ul>
</div>

下面是我如何使用分页助手。

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" }))

您的分页控件很可能位于 searchResult 容器之外。当您单击页面时,您将替换 table 而不是分页控件。将分页控件移到 searchResult 容器中!

希望对您有所帮助。