MVC 3 WebGrid Paging Does Not Return Original Search Results

I have a search page with which the webgrid is populated upon loading. My problem is with the search call. When I download, I fill out the "Unpublished" article grid (in this case, there are none). Then I search for โ€œCurrently Publishedโ€ and get 3 lines.

Now I have 3 pages (for testing, I set the swap to one line per page). The first time he searches - he gets the correct answers in the grid, nd lets you say that there are 2 pages.

If I press 2 to go to the second page - the grid is filled with load criteria - which is not published, of which there are none. I see that I will not return to the HttpPost action on the page click, so I'm not sure why it does this.

You can see that I have a bootstrap called Admin and Post called Admin (FormCollection values) On both I set the default values โ€‹โ€‹to "Not Published"

public ActionResult Admin() { var menus = ( from p in db.Menus.ToList() where p.ParentID == 0 orderby p.Order ascending select p.Name ); ViewBag.Menus = new SelectList(menus, "Home"); string[] publishedStatuses = new string[3] { "NOT PUBLISHED", "EXPIRED ALREADY", "CURRENTLY PUBLISHED"}; ViewBag.Published = new SelectList(publishedStatuses, "NOT PUBLISHED"); var articles = ( from p in db.Articles.ToList() where p.PublishToWeb == false && p.Menu == "Home" select p ); } return View(articles); } } 
0
source share
1 answer

Your problem is that the link that you click on the page will call the administrator controller again, and since you are not getting any parameters, it will do the initial search again.

If you change the action method as:

 public ActionResult Admin(int? page) { //Your code here } 

You will get the page number from the web grid and you can use it in your search. To enable filtering and search, check out this blog post:

http://www.elylucas.net/post/Using-a-grid-that-can-sort-page-and-filter-in-AspNet-MVC3e28093Part-1e28093Using-the-WebGrid-WebHelper.aspx

0
source

Source: https://habr.com/ru/post/1392156/


All Articles