I am implementing a search module with result page support paging.
The example provided by NerdDinner passes pagenumber as a parameter for the Index action, and the action uses the pagenumber to perform a query each time the user hit a different page number.
My problem is that my search take many more criteria such as price, material, model number etc. than just simple pagenumber. Therefore, I would like to preserve the criteria after users’ first submission, so that I only have to pass the pagenumber back and forth.
Using ViewData is not possible because ViewData get cleared once it is sent to the View.
Is there any good way to preserve the criteria data as I wish?
You pretty much have two ways to do this.
Put the data that you want to preserve in a serializable session, cache or the database. Putting it in the database will be the safest choice but it will degrade your performance.
You can store the preserved data in a hidden html tag. As long as the information is not sensitive this option should work well.
here is some supporting code. You can only use this within the same controller
Access the updated information like this
In the aspx page