我希望在第2页中发送搜索查询,如PageListMvc中的page1,我该怎么办? 我将查询设置为类名SearchItems:
public class SearchItems
{
public string[] productType{get;set;}
public string[] manufactureName { get; set; }
public string PriceRange { get; set; }
public string[] Capacities { get; set; }
public int[] Colors { get; set; }
}
这是我的控制器:
在我的ActionResult
中,一些参数是数组字符串。用户可以选择更多类型的项目进行搜索。
public ActionResult SearchResultByPage(int? page, string[] productType, string[] manufactureName, string PriceRange, string[] Capacities, int[] Colors,SearchItems currentFilter)
{
SearchItems se = new SearchItems()
{
productType = productType,
Capacities = Capacities,
manufactureName = manufactureName,
Colors = Colors,
PriceRange = PriceRange
};
ViewBag.currentFilter = se;
...
}
和查看:
PageListPager
已将查询作为ajax发送到参数page
和currentFilter
,并使用ViewBag.currentFilter
进行初始化。
@Html.PagedListPager((IPagedList)Model, page => Url.Action("SearchResultByPage", "Home", new{ page, currentFilter=ViewBag.currentFilter }),
PagedListRenderOptions.EnableUnobtrusiveAjaxReplacing(new AjaxOptions() { HttpMethod = "GET", UpdateTargetId = "productsContent" }))
结果网址如下:
http://localhost:22877/Home/SearchResultByPage?page=3¤tFilter=KharidHafezeh.Data.ViewModels.SearchItems