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
-
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)
- Tempdata: tempdata just persists for one request.
I really appreciate your advice!
Thank you much!
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.