Click here to Skip to main content
15,066,156 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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"})
                        )


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.
Posted
Updated 7-Sep-16 20:20pm

1 solution

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" })
                        )



These ViewBag objects initialized in controllers action method.

Anyone having better solution than this for the above problem. Please suggest.
   
Comments
Umesh AP 12-Sep-16 5:41am
   
Hi All,
Can anyone suggest alternate & better solution for this.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900