Retain data from views while navigating through multiple views in ASP.NET MVC App

asp.netasp.net-mvcretainviews

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?

Best Answer

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.