我有一個pagedList的問題。ASP.NET MVC過濾pagedlist
我有一個任務,使過濾器面板和分頁列表視圖。
我的觀點:
指數: 這是主視圖
@model WebUI.Areas.Admin.Models.Product.ProductSearchViewModel
<div class="row">
<div class="panel panel-default">
<div class="panel-heading text-center">
<h4 class="panel-title">
<a data-toggle="collapse" href="#filter">@Resources.Lang.Filter</a>
</h4>
</div>
<div id="filter" class="panel-collapse collapse">
<div class="panel-body">
@using (Ajax.BeginForm("ProductsList", "Product", new AjaxOptions { UpdateTargetId = "productsList" }, new { @id = "searchForm", @class = "form-horizontal" }))
{
// some items to filter
}
</div>
</div>
</div>
</div>
<div id="productsList" class="row">
// Here will be rendered partial view with pagedList
</div>
與pagedList
@using PagedList.Mvc
@model PagedList.IPagedList<WebUI.Models.Product.RegularProductDomainModel>
@foreach (var item in Model)
{
@Html.Partial("_ProductSummary", item)
}
Страница @(Model.PageCount < Model.PageNumber ? 0 : Model.PageNumber) из @Model.PageCount
@Html.PagedListPager(Model, page => Url.Action("ProductsList", page = page}),
PagedListRenderOptions.EnableUnobtrusiveAjaxReplacing(new AjaxOptions() { HttpMethod = "POST", UpdateTargetId = "productsList" }))
控制器
public ActionResult Index()
{
}
[HttpPost]
public ActionResult ProductsList(ProductSearchViewModel model, int page = 1, int pageSize = 5)
{
using (_unitOfWork = _factory.Create())
{
// prepare list of items
var products = _unitOfWork.ProductsRepository.GetProducts(model.CategoryID, model.BrandID, model.ProductStateID,null,true, model.Code)
.ToPagedList(page, pageSize);
return PartialView("_ProductsList", products);
}
}
˚F局部視圖過濾效果很好。但如果我想過濾值,然後做分頁它不起作用,因爲當我點擊分頁時,在控制器中,我的ProductSearchViewModel 只有默認值。據我所知這不起作用,因爲我的PartialView不知道任何關於ProductSearchViewModel,這是在Index.chtml中使用。當我做分頁時,有什麼辦法可以將我的ProductSearchViewModel傳遞給控制器嗎?