views:

139

answers:

1

Hi,

I have decided to use ASP.NET MVC to develop multi page (registration) forms in asp.net. There will be two buttons on each page that allows the user to navigate to the previous and next page. When the user navigates back to a page they recently filled out, the data should be displayed to them. I understand ASP.NET MVC should remain stateless but how should I maintain page information when the user navigates back and forth.

Should I?

  1. Save the information to a database and retrieve information for each page change?
  2. save information to the session?
  3. Load all the fields and display only whats's needed with javascript?

This registration form is going to be used in multiple sites but with different sets of questions (Some may be the same). IF performance is a main concern, should I avoid generating these forms dynamically?

Jay

+2  A: 

This sounds like the kind of information that you would want to store in a user session. What session store is used can be configured, so you could use a database to store session for users if that would be a better fit than using in-process session.

Russ Cam
Depending how far you want to go and how much DI you are using, you may want to hide the actual storage mechanism behind an interface so you can swap implementation at a later date if your needs change
Neal
@Neal - good point. I think you just need to implement `IHttpSessionState` - http://msdn.microsoft.com/en-us/library/system.web.sessionstate.ihttpsessionstate.aspx
Russ Cam
Neal do you mean using a seperate interface to implement saving the information into a database or saving session state into the db?
Jay
Create a simple interface e.g. IWorkflowState with 2 methods Store and Retrieve. Create an implementation of that to act as a facade to session state. This means you can easily test by mocking IWorkflowState and if you decide to change to storing the data in the database you simply change the implementation.
Neal
Neal - great pattern. In MVC you can easily mock the whole context so you could do it with or without a facade
Russ Cam
thanks for the help guys!
Jay