Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP .NET MVC Storing Lots of Parameters between Views

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?

like image 297
Lance Avatar asked Nov 04 '22 06:11

Lance


2 Answers

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.

like image 97
PinnyM Avatar answered Nov 11 '22 16:11

PinnyM


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.

like image 35
Greg B Avatar answered Nov 11 '22 16:11

Greg B