I have 5 views in my ASP.NET MVC application. Some data were captured from these views and I am navigating through these views using 2 buttons: the Previous and Next buttons.
So I fill 开发者_如何学编程the data in View 1 and I go to view 2 and enter the data there and so on.. till View 5.
Now the question is: If I come back again to previous views, how to retain the data entered there in that particular view.
In addition, I want to submit the data from all the 5 views at a time, once I finish entering data to all 5 views.
What is the best way to do it?
I can think of a number of approaches to your issue. You could create a single view with a number of 'panels' which are hidden or revealed depending on which step you are on in the process, like a wizard control. You could try and use a cookie but that's not very clean. Ideally, you embrace the statelessness of the MVC pattern and the fact the View is a view of the Model and update your Model as each page posts back to your Controller and you persist the Model (however you choose) between pages.
Simplicity might lead me to suggest the 'wizard' approach if you don't want to persist anything until the process is complete. I'm certain jQuery could help you out with this solution.
If you only want to submit the content once all pages are filled, you will probably need to store entered data into a cookie on the client machine. You can do this with javascript:
http://www.quirksmode.org/js/cookies.html
精彩评论