Last post Apr 03, 2012 08:32 AM by Young Yang - MSFT
Mar 27, 2012 01:09 PM|SanjaySutar|LINK
I have 2 Search actions one for get and other for
public ActionResult Search()
/*code to populate dropdowns, listboxes and other controls that form search criteria
public ActionResult Search(FormCollection collection)
/*get search criteria from Formcollection and get data*/
List<SearchSummary> searchRecords = summaryList.Summaries;
ViewBag.Records = searchRecords;
Now i am using a WebGrid to show all records. I am not getting any data when i am clicking on
Grid SortColumn and Page number links.
This is happening because it is going for first Search() whereas all data fetch login is in another method
Please help me understand how to fix this. Also plz provide any gud site with gud example on webgrid.
Thanks in advance.
Mar 27, 2012 04:33 PM|CodeHobo|LINK
What does the code in the view look like? Specifically where the webgrid is declared.
It looks like you are fetching the data in the HTTP post search action, I believe by default the web grid pages data by performing an http get (the first option). If you do not want to use ajax, then you have to repopulate the grid data.
Another thing to be careful of is that you are getting your data as a list instead of an IQueryable. In this case even if the grid has paging, you are pulling ALL the data from the database, which would cause a performance hit over large sets of data.
Mar 27, 2012 04:45 PM|SanjaySutar|LINK
thanks for the reply....
I am populating on HTTP Post because I have to populate grid on click of a "Search" button.
The grid gets populated, but when i click on any sort column or page number, it goes back to HTTP Get action.
Also I would change the code to return IQueryable object.
At the moment i am concernd about sort columns and page number links
What is the right way to implement the grid ??? Any example of that ??
Apr 03, 2012 08:32 AM|Young Yang - MSFT|LINK
I don't think you need the Search action. You just need pass the data in the Index action, and specify two paramters, one is sortOrder and anothers one is page.
For details, you can have a looke:
Hope this helpful