1

I have 6 pages, each with their own form, and a model associated with that form. What I would like to be able to do is store all the information on all 6 forms so that the user can go between any of the 6 pages and still have their previous work saved. The idea is that the user should be able to fill out the forms on the pages in any order and return to their work at any time.

What is the best way to maintain all of this information? Should I create a super model that has all of the other models and only pass this model around to the other pages? thank you!

tereško
  • 58,060
  • 25
  • 98
  • 150
John Edwards
  • 1,536
  • 3
  • 14
  • 33

2 Answers2

3

Fetch (from a data source) what data is relevant to the current page and show it.If you want to show all the data in a page (Ex : A summary page of all the pages, Create a view model which holds all the data). You can fetch data from a variety of source like DB tables/Web Service/XML file/Cached data /Session etc..

Each of views can bind to individual view models.

public class AddressVM
{
  //properties for address page
}

public class BillingInfo
{
  //properties for Billing Info page
}

public class OrderSummaryVM
{
 public AddressVM ShippingAddress {set;get;}
 public BillingInfo BillingDetails {set;get;}
}

The summary page can be binded to the OrderSummaryVM class while the individual pages can be binded to AddressVM and BillingInfoVM classes

Shyju
  • 214,206
  • 104
  • 411
  • 497
  • I agree, this looks like a good application for a backing data store. – neontapir May 24 '13 at 21:27
  • Sorry, I am not following. If I have Page A and Page B, and a PageAModel and PageBModel, when I postback to Page A, the user's inputs are saved(thanks to model binding). If I click on Page B, then click back to Page A, how do I keep the changes they made to Page A originally? I do not understand how to do this from your answer. Sorry and thank you. – John Edwards May 24 '13 at 21:32
  • @JohnEdwards: When you go back to Page, Read the data from the data source (your db / XML file/ Webservice/ Session/Cache) and load it there. – Shyju May 24 '13 at 21:33
  • That makes sense, but how do I save what the user has done when they click another link? – John Edwards May 24 '13 at 21:45
  • @JohnEdwards: Using javascript-jquery, listen to the click event on the link, read the form data, make an ajax call to an action method with the data, Save the data in the action method. You can serialize the entire form and send to your action method. Model binding will work for this too. – Shyju May 24 '13 at 21:48
  • Thanks. I will have to learn some JQuery, as I have no experience with it or the client side magic you can do. I am confused at the model binding comment though. Model binding would work for what? I can use model binding for the save method INSTEAD of serializing? – John Edwards May 24 '13 at 22:19
  • @JohnEdwards: Model binding will work when you post the form data asynchronously (jQuery ajax). – Shyju May 25 '13 at 15:12
1

What your are looking for is how to manage session in a MVC application.

There are several ways to do so.

You could use ViewData, ViewBag, TempData or Session

Another way to do it would be to have only one page with the six forms. The user would navigate through the form using javascript to show/hide appropriate content. At the end he would submit all the data to your controller. You could save the data in a cookie so that if he close and reopen the browser he still sees what he entered.

alexandrekow
  • 1,927
  • 2
  • 22
  • 40
  • The big problem with the last suggestion, is what happens when JS is disabled. You either have a page with all 6 forms' fields (rather overwhelming), or stuff just doesn't work. – cHao May 25 '13 at 13:27
  • Sure it depends on the website requirement. There is only a small percentage of people with javascript disabled. http://stackoverflow.com/questions/9478737/browser-statistics-on-javascript-disabled However it is indeed something to keep in mind. – alexandrekow May 25 '13 at 15:06