试图让 MvcPaging 在 Ajax 模式下工作,但它不合作!它可以工作,但会执行完整的 GET 而不是 Ajax 调用。当我进入控制器代码 Request.IsAjaxRequest() 为假时,表明它无法正常工作。下面是我的剃刀视图和控制器代码:
@using MvcPaging
@model IPagedList<PracWare.Net.patientnote>
@Scripts.Render("~/bundles/jquery")
<link href="~/Content/paging.css" rel="stylesheet" />
<link href="~/Content/Bootstrap2.3.1.css" rel="stylesheet" />
<div id="notes-list">
<table width="98%">
<tr><th>Date</th><th>Notes</th></tr>
@foreach (var note in Model)
{
<tr><td>@note.dateTime</td><td>@note.notes</td></tr>
}
</table>
<div id="paging-control">
@Html.Raw(Ajax.Pager(
new Options
{
PageSize = 5,
TotalItemCount = Model.TotalItemCount,
CurrentPage = Model.PageNumber,
ItemTexts = new ItemTexts() { Next = "Next", Previous = "Previous", Page = "P" },
ItemIcon = new ItemIcon() { First = "icon-backward", Previous = "icon-chevron-left", Next = "icon-chevron-right", Last = "icon-forward" },
TooltipTitles = new TooltipTitles() { Next = "Next page", Previous = "Previous page", Page = "Go to page {0}.", First = "Go To First Page", Last = "Go To Last Page" },
Size = Size.normal,
Alignment = Alignment.centered,
IsShowControls = true,
IsShowFirstLast = true,
},
new AjaxOptions
{
UpdateTargetId = "notes-list",
OnBegin = "beginPaging",
OnSuccess = "successPaging",
OnFailure = "failurePaging"
}, new { controller = "Patient", action = "JqAjaxOrders"}))
</div>
</div>
和控制器代码:
public ActionResult JqAjaxOrders(int? page)
{
var db = new PracwareEntities();
var orders = db.patientnotes.OrderBy(o=>o.dateTime).ToPagedList(page ?? 1, 5);
if (Request.IsAjaxRequest())
return PartialView("JqAjaxOrders", orders);
return View(orders);
}
我直接从 MvcPagingDemo 解决方案中获取了这段代码,该解决方案确实正确地执行了 Ajax 调用。我可能错过了什么?