views:

142

answers:

2

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?

A: 

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

Paul
+2  A: 

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.

Lazarus
If putting all the forms on one view is acceptable, and you are using jQuery, I strongly recommend checking this out: http://www.jankoatwarpspeed.com/post/2009/09/28/webform-wizard-jquery.aspx
Paul
can you explore mr more on "you persist the Model (however you choose) between pages"Once i updated the model for one view how i can get back my data from the model ?
Nagendra Baliga
As you move from page to page you do so by using the Html.ActionLink helper method to construct a link which passes a unique reference (probably the record key for the current record from your Model) to the next page, i.e. Html.ActionLink("page2", id = Model.ID). Using the basic routing normally found in a new MVC project in Visual Studio you'll have the Controller/Action/ID path which would cover the example above. I can't recommend Steven Sanderson's book on ASP.NET MVC enough (http://www.apress.com/book/view/1430210079)
Lazarus