Orchard CMS 默认寻呼机问题
Posted
技术标签:
【中文标题】Orchard CMS 默认寻呼机问题【英文标题】:Orchard CMS default Pager issues 【发布时间】:2015-04-17 07:47:01 【问题描述】:场景是这样的:
一个投影总共有 13 个项目。默认情况下,Orchard 显示 2 页(第 1 页为 10,第 2 页为 3)。如果用户在第二页然后选择显示 50 的选项,那么 Orchard 会在 url 中留下 ?page=2 并且它会弄乱寻呼机。显示 51-13 项,共 13 项。 Orchard 背后的社区已经填写了一个错误报告,但我认为有人可以帮助解决这个问题,因为它是一个小代码 sn-p。我猜想最后的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>
【问题讨论】:
作为临时解决方案,我删除了选择要显示多少项目的选项。 你可以做一个额外的检查,比如:var currentPage = Model.Page > totalPage ? Model.Page - 1 : Model.Page;
,然后使用currentPage
而不是Model.Page
我已经修改了下面的行,添加了 && key != "page" 到它: if (key != null && !routeData.ContainsKey(key) && key != "page")
【参考方案1】:
我在codeplex 上找到了修复方法
我会试一试的。
【讨论】:
以上是关于Orchard CMS 默认寻呼机问题的主要内容,如果未能解决你的问题,请参考以下文章
ASP.Net CMS 推荐、Orchard、Sitefinity、Umbraco 还是 N2? [关闭]