搜索&在MVC中使用AJAX分页进行排序 [英] Searching & sorting with AJAX pagination in MVC
问题描述
我正在使用搜索,分页和排序开发MVC4应用程序。普通视图下一切正常。
现在我使用Ajax&转换同样的应用程序局部视图。
如何通过我的搜索&通过驻留在部分View上的Paging控件对参数进行排序。现在,我能够在部分视图中加载过滤后的数据,但移动到下一页,丢失了我的搜索参数并加载了忽略搜索过滤器的所有记录。
_PartialView.cshtml中的我的分页控件
I am developing MVC4 application with Searching, Paging and Sorting. Everything works fine with normal view.
Now I am converting same application using Ajax & Partial View.
How can I pass my search & sort parameter through Paging control residing on partial View. Now, I am able to load filtered data in partial view but moving to next page, lost my search parameters and loads all records ignoring search filters.
My Paging Control in _PartialView.cshtml
@Html.PagedListPager(Model,
page => Url.Action("AjaxMethod",
new
{
page,
searchByUserName = Request.QueryString["searchByUserName"],
searchByReaderName = Request.QueryString["searchByReaderName"],
searchByReaderType = Request.QueryString["searchByReaderType"],
searchByUploadDate = Request.QueryString["searchByUploadDate"],
sortBy = Request.QueryString["sortBy"]
}),
//new PagedListRenderOptions.() { Display = PagedListDisplayMode.IfNeeded, DisplayPageCountAndCurrentLocation = true }
PagedListRenderOptions.EnableUnobtrusiveAjaxReplacing( new AjaxOptions(){ HttpMethod = "GET", UpdateTargetId = "divData"})
)
请建议,我缺少什么。
我尝试过:
我是MVC开发的新手。谷歌搜索了很多这个问题,但找不到合适的解决方案。
Please suggest, what I am missing.
What I have tried:
I am new to MVC development. Googled a lot for this issue but can't find appropriate solution.
推荐答案
Hello Guys,
我开始知道自己错过了什么,部分视图没有得到Request.QueryString值,这就是分页控制丢失搜索参数并加载所有记录的原因。所以我在_PartialView.cshtml中修改了Pager控件,如下所示:
Hello Guys,
I came to know what I m missing, Partial View doesn't got Request.QueryString values thats why paging control lost search parameters and loads all records. So I modified Pager control in _PartialView.cshtml as follows :
@Html.PagedListPager(Model,
page => Url.Action("AjaxMethod",
new
{
page,
searchByUserName = ViewBag.searchByUserName, // Request.QueryString["searchByUserName"],
searchByReaderName = ViewBag.searchByReaderName, // Request.QueryString["searchByReaderName"],
searchByReaderType = ViewBag.searchByReaderType, // Request.QueryString["searchByReaderType"],
searchByUploadDate = ViewBag.searchByUploadDate, // Request.QueryString["searchByUploadDate"],
sortBy = ViewBag.sortBy // Request.QueryString["sortBy"]
}),
PagedListRenderOptions.EnableUnobtrusiveAjaxReplacing(new AjaxOptions()
{ HttpMethod = "GET", UpdateTargetId = "divData", LoadingElementId="divloading" })
)
这些ViewBag对象在控制器操作方法中初始化。
任何人都有比这更好的解决方案以上问题。请建议。
These ViewBag objects initialized in controllers action method.
Anyone having better solution than this for the above problem. Please suggest.
这篇关于搜索&在MVC中使用AJAX分页进行排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!