how could i persist the page state after page redirect in asp.net MVC?
i have some search filed and a gri开发者_Python百科dview, if i jump to another page and when it redirect to back, all of the states will not persist, i could create a search model to save the data and keep it in the session, but the search will in some page and the fields are not fixed. is there a good way to solve this?
The general options are to store it in TempData so it is available upon the next request OR store it in the cache OR reload it OR store it in the session for longer persistence. This is how the web works as far as being stateless so you need to figure one of these general methods. Cookies are quite limited so I would exclude them in this case.
Ideally - if you use the repository pattern for loading your data, in your repository method you can add the data to the cache by the current user's login id - if the data makes sense to cache. If you only want it available for the next request, add it to TempData["YourData"] = yourObject
After you read it on the next request it will then automatically be flagged for deletion at the end of the request processing.
I'm working on a similar problem and found this helpful:
http://weblogs.asp.net/rashid/archive/2009/04/01/asp-net-mvc-best-practices-part-1.aspx#prg
精彩评论