Search model is getting cleared for second page request in PagedList.MVC in MVC

痴心易碎 提交于 2019-12-08 21:07:31

Add a property to your view model for the IPagedList<T> and then return your model, so the search/filter values can be added to the url

public class SearchModel
{
    public string search_text { get; set; }
    public string min_area { get; set; }
    ....
    IPagedList<yourModel> Items { get; set; }
}

public ActionResult GetSearchdProperty(int? page, SearchModel model)
{
    model.Items = db.re_advertise.OrderBy(r => r.id).ToPagedList(pageNumber: page ?? 1,pageSize: 2));
    return View("SearchedProperty", model);
}

and in the view

@model SearchModel
....
@Html.PagedListPager(Model.Items, page => Url.Action("GetSearchdProperty", "SearchProperty", 
    new { page, search_text = Model.search_text, min_area = Model.min_area, .... }))
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!