Orchard CMS 默认寻呼机问题

Orchard CMS default Pager issues

场景是这样的:

投影中共有13个项目。默认情况下,Orchard 显示 2 页(第一页 10 页,第二页 3 页)。如果用户在第二页然后选择显示 50 的选项,那么 Orchard 会在 url 中留下 ?page=2 并且它会弄乱寻呼机。显示第 51-13 项,共 13 项。 Orchard 背后的社区已经充满了错误报告,但我认为有人可以帮助解决这个问题,因为它是一个小代码片段。我想最后的 Javascript 需要修改,但我不太确定...

pager.cshtml(从 AdminView 复制):

@{
Model.PreviousText = T("<");
Model.NextText = T(">");

var routeData = new RouteValueDictionary(ViewContext.RouteData.Values);
var queryString = ViewContext.HttpContext.Request.QueryString;
if (queryString != null) {
    foreach (string key in queryString.Keys) {
        if (key != null && !routeData.ContainsKey(key)) {
            var value = queryString[key];
            routeData[key] = queryString[key];
        }
    }
}

if (routeData.ContainsKey("id") && !HasText(routeData["id"])) {
    routeData.Remove("id");
}

var totalPageCount = (int)Math.Ceiling((double)Model.TotalItemCount / Model.PageSize);

Model.Metadata.Type = "Pager_Links";
IHtmlString pagerLinks = Display(Model);

Model.Classes.Add("selector");
var pageSizeTag = Tag(Model, "ul");

if (Model.RouteData != null) {
    foreach (var rd in Model.RouteData.Values) {
        routeData[rd.Key] = rd.Value;
    }
}

var pageSizes = new List<int?> { 10, 50, 100 };
var defaultPageSize = WorkContext.CurrentSite.PageSize;
if (!pageSizes.Contains(defaultPageSize)) {
    pageSizes.Add(defaultPageSize);
}

Script.Require("jQuery");
}

@if (Model.TotalItemCount > 1) {
<div class="pager-footer">
<span class="page-results">@T("Showing {0} - {1} of {2} jobs", (Model.Page - 1) * (int)Model.PageSize + 1, Model.PageSize == 0 ? Model.TotalItemCount : Math.Min(Model.TotalItemCount, (Model.Page) * (int)Model.PageSize), Model.TotalItemCount)</span>
    @if (totalPageCount > 1 || Model.PageSize == 0 || Model.PageSize > pageSizes.First()) {
        <div class="page-size-options group">
@T("Show:") @pageSizeTag.StartElement

                @{ routeData["pageSize"] = 0; }

                @if ((int)Model.PageSize == 0) {
                    <li class="selected"><span>@T("All").ToString()</span></li>
                } else {
                    <li>@Display.ActionLink(Value: T("All"), Action: (string)routeData["action"], Controller: (string)routeData["controller"], RouteValues: routeData)</li>
                }

                @foreach (int size in pageSizes.OrderBy(p => p)) {
                    routeData["pageSize"] = size;

                    if ((int)Model.PageSize == size) {
                        <li class="selected"><span>@size.ToString()</span></li>
                    } else {
                        <li>@Display.ActionLink(Value: size, Action: (string)routeData["action"], Controller: (string)routeData["controller"], RouteValues: routeData)</li>
                    }
                }

                @pageSizeTag.EndElement
        </div>
    }
@if (totalPageCount > 1 || Model.PageSize != 0) {
@pagerLinks
} 
</div>
}
@using (Script.Foot()) {
<script type="text/javascript">
//<![CDATA[
$(function () {
    $('ul.selector').each(function () {
        var self = $(this),
            options = $.map(self.find("li"), function (li) {
                var self = $(li);
                return $("<option/>", {
                    value: self.children("a").attr("href"),
                    text: self.text(),
                    selected: self.hasClass("selected")
                })[0];
            }),
            select = $("<select/>", {
                id: self.attr("id") + "Selector",
                "class": self.attr("class"),
                name: self.attr("name") + "Selector"
            }).change(onSelectChange).append(options);
        self.replaceWith(select);
    });

    function onSelectChange() {
        // redirect to page with new page size
        // disable button so that no other value can be chosen while the form is submited
        window.location = $(this).attr("disabled", true).val();
    }
})
//]]>
</script>
}

我在 codeplex

上找到了修复

我试试看