MVC3异步分页和查询
将Pager里面的东西重新生成
Controller里面写方法:
#region 分页方法三(异步分页)
public ActionResult List(int? id, int? recorderID, DateTime? recordTime)
{
int pageSize = 3;
PagedList<tbGoods> goods = null;
if (recordTime != null && recorderID != null)
{
goods = db.tbGoods.OrderBy(p => p.recordTime).Where(s => s.recordUserID == recorderID && s.recordTime == recordTime).ToPagedList(id ?? 1, pageSize);
}
else if (recordTime == null && recorderID != null)
{
goods = db.tbGoods.OrderBy(p => p.recordTime).Where(s => s.recordUserID == recorderID).ToPagedList(id ?? 1, pageSize);
}
else if (recordTime != null && recorderID == null)
{
goods = db.tbGoods.OrderBy(p => p.recordTime).Where(s => s.recordTime == recordTime).ToPagedList(id ?? 1, pageSize);
}
else
{
goods = db.tbGoods.OrderBy(p => p.recordTime).ToPagedList(id ?? 1, pageSize);
}
ViewBag.recorderID = new SelectList(db.tbUsers.Where(u => u.usercode != "qc"), "userid", "username");
if (Request.IsAjaxRequest())
return PartialView("GoodsList", goods);
return View(goods);
}
#endregion
List页面:
@using MvcFinance.Pager
@model PagedList<MvcFinance.Models.tbGoods>
<script src="../../Scripts/jquery.unobtrusive-ajax.min.js" type="text/javascript"></script>
@using (Ajax.BeginForm(new AjaxOptions { UpdateTargetId = "divExpenseList", HttpMethod = "Get" }))
{
<p>购买者:@Html.DropDownList("recorderID", "请选择") 购买时间: @Html.TextBox("recordTime", "", new { onclick = "WdatePicker()" })
<input type="submit" value="查询" /></p>
}
<div id="divExpenseList">
@{Html.RenderPartial("GoodsList", Model); }
</div>
GoodsList页面:
@using MvcFinance.Pager
@model PagedList<MvcFinance.Models.tbGoods>
<div id="dvGoods">
<table>
<tr>
<th>
goodsNumber
</th>
</table>
@Html.AjaxPager(Model, new PagerOptions()
{
CssClass = "mvcPager",
PageIndexParameterName = "id",
ShowMorePagerItems = false,
AlwaysShowFirstLastPageNumber = true,
ShowPageIndexBox = true,
PageIndexBoxWrapperFormatString = "页{0}"
},
new AjaxOptions() { UpdateTargetId = "dvGoods" })
</div>