John Edwards
John Edwards

Reputation: 1546

ASP.NET MVC Model Design

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!

Upvotes: 1

Views: 340

Answers (2)

Shyju
Shyju

Reputation: 218882

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

Upvotes: 3

alexandrekow
alexandrekow

Reputation: 1937

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.

Upvotes: 1

Related Questions