datatest
datatest

Reputation: 473

multi page form. where do I save the previous data?

So I have a 7 step form, which will have the ability to go the the previous steps. using mvc, is it best to create one large view model and have the 7 steps all in one page, but only displaying certain sections? Or should I divide it up between pages/views?

Upvotes: 1

Views: 2108

Answers (3)

sakura-bloom
sakura-bloom

Reputation: 4604

I worked on a 12-page form before in ASP.NET MVC. Each page of the form was long and I stored data after each page's submission. I had a separate table (model class) for each page and a corresponding view model for each view. When you navigate back to some previous page you simply retrieve data for that page.

I was also storing the last completed page number in a database for navigation purposes. Users could log out and come back later to finish the form and they would be redirected to the page where they left off.

Upvotes: 1

Win
Win

Reputation: 62301

SessionState will be a good choice for saving the previous page's data.

For example,

Page 1

var customer = new Customer
{
  FirstName = "John",
};    
Session["Customer"] = customer;

Page 2

var customer = Session["Customer"];
customer.Address1 = "123 Street";
Session["Customer"] = customer;

Upvotes: 4

Joshua Wilson
Joshua Wilson

Reputation: 2536

I would suggest that you save the data in Model part of your MVC. Break your form up so that it is easiest to understand and process from the users point of view. Once they are done with the form you can send your data in your Model over to the server to be processed. Or you can allow them to make changes as needed.

If your data structure is complex then you make a Model that represents it as best as possible, it will be easier to handle then.

Upvotes: 1

Related Questions