3

I'm planing to build a multi-step form with asp.net mvc 2. So, my web application will have 5 pages correspond to 5 steps. Each step has two submit buttons, previous and next. Input data for each step will be stored for reviewing later. For example, we already inputted data for step s 1,2,3,4 and we are in step 5 now. When I click on "previous" 2 times, step 3 should be displayed with data I inputted before. Similar, when I click "next", inputted data should also be retained in step 4 (since we are in step 3 now) Model used for each step can be very different.

I'm seeking a solution to save data for each step. I'm thinking about session and tempdata, both of them have disadvantages which I have to consider to use

  1. Session

    • Default session is cookie session, so session will not work well if web browser doesn't have cookie enabled. I also have a concern here, when IE doesn't have cookie anabled, session variable will be lost only in the case actor uses hostname to access web application. Session works fine in IE with ip address url.
    • Cookies less session: not safe, have many constrains and have an issue with post (http://stackoverflow.com/questions/3972433/mvc2-cookieless-session-issue-using-post or http://forums.asp.net/p/1517391/3634908.aspx)
  2. Tempdata: tempdata just persists for one request.

I really appreciate your advice!

Thank you much!

khoailang
  • 725
  • 1
  • 15
  • 32

4 Answers4

2

I always use session. I've seen you concern about the persons not using cookies, but i don't think that is a problem these days as i don't think there are many users denying cookies.

My preference for session is that it's easy to store and retrieve and easy to setup. When you scale out (to more servers) you can easyly setup your application to store the the sessionstate in a sql server database so you're ready for the future too.

Hidden fields i use sometimes when there is not sensitive information stored between the steps, because the user can edit the value of the hidden fields.

If there is a lot of info to share between the posts and you don't want a lot of hidden fields, you can also create an object for your storage (like you would create when you would stoe it in session) and the serialize the object, base64 encode it and store it in ONe hidden field.

Michel
  • 23,085
  • 46
  • 152
  • 242
  • thanks Michel, I prefer session too. But I have a big concern posted in another thread http://stackoverflow.com/questions/4303579/session-lost-when-using-hostname-instead-of-ip-address-ie. Session variables will be null when MVC is deployed in IIS and user uses IE to access the application by hostname instead of ip address. I'm curious why IE works fine with IP address url (no need to enable cookie in IE this case) and firefox also works well all cases. Do you get into the same problem with me? Thank you for sharing information – khoailang Nov 30 '10 at 02:38
  • I've read your post. It's something i've never experience myself, did you only experience it cookieless? – Michel Nov 30 '10 at 20:49
1

Are you opposed to sticking their data into the database? That way, when they go "Prev" you just pull up that page's data from the database. You could just save that page as "temp" or whatever status you want to indicate that the user hasn't officially saved it yet. Then, you don't have to worry about session or anything like that.

Nick DeVore
  • 9,748
  • 3
  • 39
  • 41
0

TempData is implemented with Session variables behind the scenes, so your concerns for about sessions extend to the use of TempData.

If the wizard was quite long and complicated I would probably persist to a DB, otherwise if it's quite small and simple you could consider storing all the data, for all steps, in form fields and posting all the data between the steps.

JonoW
  • 14,029
  • 3
  • 33
  • 31
0

I agree with JonoW, I would consider putting hidden fields to store the data between steps (has worked for me)

Francisco
  • 4,104
  • 3
  • 24
  • 27
  • thanks Fancisco, I'm thinking about your advice. Let say, I have a big model for all steps. At step one, user just needs to input only one field. So, I will one TextboxFox(...) and rest one are HiddenFor(...), correct? I'd really like to leverage the input validation capability of MVC2 so I would build a partial validation attribute likes this? (http://blog.stevensanderson.com/2010/02/19/partial-validation-in-aspnet-mvc-2/) – khoailang Nov 29 '10 at 16:59
  • above all, the session in MVC2 does have a significant meaning !?!?!? – khoailang Nov 29 '10 at 17:00