MVC 中 PagedList.MVC 中的第二页请求正在清除搜索模型
Search model is getting cleared for second page request in PagedList.MVC in MVC
我在我的 MVC 中使用 PagedList.MVC 进行分页 application.So 首先我在主页上,当我填写搜索栏并提交表单时 post 模型搜索方法,如下所示。
public ActionResult GetSearchdProperty(int? page,SearchModel objSearch)
{
var objProperty = db.re_advertise.OrderBy(r => r.id);
return View("SearchedProperty", objProperty.ToPagedList(pageNumber: page ?? 1,pageSize: 2));
}
所以这将重定向到具有搜索条件结果的搜索页面。现在,当我单击 PagedList.MVC 的第 2 页时,调用了相同的方法,但此时我的 SearchModel 为空或说空白,但我希望我的搜索模型与从分页时在所有页面请求中一样。那么我该如何实现呢?
我尝试在 VieBag
中使用搜索模型,但我不知道如何在分页请求中从视图包发送模型。我不知道如何在 Html.PagedListPager
中传递模型
@Html.PagedListPager(Model, page => Url.Action("GetSearchdProperty", "SearchProperty", new { page })).
EDIT
public class SearchModel
{
public string search_text { get; set; }
public string min_area { get; set; }
public string max_area { get; set; }
public string min_price { get; set; }
public string max_price { get; set; }
public string bedroom { get; set; }
}
将 属性 添加到 IPagedList<T>
的视图模型,然后 return 您的模型,这样 search/filter 值可以添加到 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);
}
并在视图中
@model SearchModel
....
@Html.PagedListPager(Model.Items, page => Url.Action("GetSearchdProperty", "SearchProperty",
new { page, search_text = Model.search_text, min_area = Model.min_area, .... }))
我在我的 MVC 中使用 PagedList.MVC 进行分页 application.So 首先我在主页上,当我填写搜索栏并提交表单时 post 模型搜索方法,如下所示。
public ActionResult GetSearchdProperty(int? page,SearchModel objSearch)
{
var objProperty = db.re_advertise.OrderBy(r => r.id);
return View("SearchedProperty", objProperty.ToPagedList(pageNumber: page ?? 1,pageSize: 2));
}
所以这将重定向到具有搜索条件结果的搜索页面。现在,当我单击 PagedList.MVC 的第 2 页时,调用了相同的方法,但此时我的 SearchModel 为空或说空白,但我希望我的搜索模型与从分页时在所有页面请求中一样。那么我该如何实现呢?
我尝试在 VieBag
中使用搜索模型,但我不知道如何在分页请求中从视图包发送模型。我不知道如何在 Html.PagedListPager
@Html.PagedListPager(Model, page => Url.Action("GetSearchdProperty", "SearchProperty", new { page })).
EDIT
public class SearchModel
{
public string search_text { get; set; }
public string min_area { get; set; }
public string max_area { get; set; }
public string min_price { get; set; }
public string max_price { get; set; }
public string bedroom { get; set; }
}
将 属性 添加到 IPagedList<T>
的视图模型,然后 return 您的模型,这样 search/filter 值可以添加到 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);
}
并在视图中
@model SearchModel
....
@Html.PagedListPager(Model.Items, page => Url.Action("GetSearchdProperty", "SearchProperty",
new { page, search_text = Model.search_text, min_area = Model.min_area, .... }))