I have a very simple ASP.NET MVC site which displays images from the database. The user fills out some search parameters and a View returns a list of images from the database which match the search criteria.
I'm now adding Pagination, where depending on the page number I skip a certain number of images retrieved from the database. I've got this working for the first page. My search parameters are lost when I click on the second page of results as I have no mechanism in place to store the search parameters between Views at the moment.
What's the best approach to take. I could have lots of search parameters. Should I store them all in the Session or in hidden fields? That feels like a hack. Should I have a seperate ViewModel to hold the search params and store that in the Session?
What's the typical approach to take?
You would typically store cross-pagination data in hidden fields. For scalability, sessions should be limited to session-wide related data. If putting the data in hidden fields opens a vulnerability, you can consider serializing a view model and encrypting it as one hidden field. Putting it in the URL is another option, although you are limited to the amount of content you can put there.
I would put them all in the querystring of your "Next" and "Previous" links. This would allow visitors to bookmark the full URL and return to the same page with the same sort and filter settings.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With