如何将搜索查询发送到PagedListPager Asp.net mvc

时间:2016-10-01 06:08:00

标签: asp.net-mvc pagedlist

我希望在第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发送到参数pagecurrentFilter,并使用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&currentFilter=KharidHafezeh.Data.ViewModels.SearchItems

0 个答案:

没有答案