我在搜索操作结果中使用分页列表来分页我的结果。它返回日期范围或类别内的事件。返回的第一页很好,但第二页没有任何结果。当我检查断点时,查询返回超过 7 个结果。这是我的搜索控制器;
public ActionResult Search(DateTime? q, DateTime? e, int? EventCategoryId, Event model)
{
var SearchEvents = db.Events
.OrderByDescending(r => r.start)
.Where(r =>
r.start >= q &&
r.end <= e &&
r.EventCategoryId == EventCategoryId ||
r.start >= q ||
r.EventCategoryId == EventCategoryId);
ViewBag.QValue = model.start;
ViewBag.EValue = model.end;
ViewBag.ListValue = model.EventCategoryId;
ViewBag.EventCategoryId = new SelectList(db.EventsCategories, "Id", "Name", ViewBag.ListValue);
var pageIndex = model.Page ?? 1;
var results = SearchEvents.ToPagedList(pageIndex, 4);
ViewBag.Names = results;
return View(results);
}
}
这是我的观点;
@model IPagedList<RealKaac.Models.Event>
@{
ViewBag.Title = "SearchResults";
}
@using PagedList;
@using PagedList.Mvc;
@using System.Linq;
<div id="Content">
<h2>SearchResults</h2>
<div id="EventSearch">
@using (Html.BeginForm("Search", "Event"))
{
<p class="EventPar">Start Date: </p>
<input id ="datepicker" type ="text" name ="q" value="@ViewBag.QValue" />
<p class="EventPar">End Date: </p>
<input id ="datepickerend" type ="text" name ="e" value ="@ViewBag.EValue" />
<p class="EventPar">Category:</p>
@Html.DropDownList("EventCategoryId")
<input id="EventButton" style="padding:1px;" type ="submit" name ="Search" value = "Search" />
}
</div>
<div id="IndexEvents">
@foreach (var item in Model)
{
<div class ="event">
<div class="eventname">
@*<p>@Html.DisplayFor(modelItem => item.Name)</p> *@
</div>
<div class = "etitle">
<p>@Html.DisplayFor(modelItem => item.title)</p>
</div>
<div class="eventsdesc">
<p>@Html.DisplayFor(modelItem => item.EventDescription)</p>
</div>
<ul class ="datelink">
<li style="margin-right:120px;">This event starts on the
@Html.DisplayFor(modelItem => item.start) and ends on the
@Html.DisplayFor(modelItem => item.end)</li>
<li>Click @Html.DisplayFor(modelItem => item.EventWebsite) for more info.</li>
</ul>
</div>
}
</div>
</div>
@Html.PagedListPager((IPagedList)ViewBag.Names, page => Url.Action("Search", new { page }))
我对此很陌生,所以我可能遗漏了一些小东西,非常感谢任何建议。
谢谢。