Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Persist List of Objects Between Pages - ASP MVC

C# - ASP MVC - .NET 4.5 - Bootstrap - Razor

I have a form wizard (http://vadimg.com/twitter-bootstrap-wizard-example/examples/basic.html) that is used to setup a complex object (obj1). A property of obj1 is a List<obj2>. On one step of the wizard I want to add multiple obj2's to the list. Since obj2 is slightly complex as well, I thought I would use another wizard to help build it. Except I need to persist this List<obj2> on wizard 1, while I'm off in wizard 2 building another obj2.

My first thought was to use a session to hold the List<obj2>, I was just wondering if that's a good option, or if there would be a better one? The user may leave from Wizard1 to go to Wizard2 and come back multiple times.

like image 880
Will Avatar asked Dec 11 '25 05:12

Will


1 Answers

There's no perfect answer here; each approach has trade-offs. But here are some options that I can think of (and these are independent of ASP.NET/C#)

  • Session (as you suggest)
    • This will store data in web server memory (by default). If you have a lot of users, this could be a problem.
    • You risk the information being lost when the user gets a new cookie/the session times out.
    • Potentially better performance that a db, depending again on the number of users
  • Database (as you mentioned)
    • Could cause more database traffic.
    • Can save information for user even if they close a browser, switch computer, the power goes out, etc.
    • Maybe a separate NoSQL database just for transient wizard data would be worth trying.
  • Cookie (store data on the user's computer)
    • Users can potentially tamper with/view the data
    • There is a limit on cookie size (4 KB each?)
  • Local storage (HTML5)
    • Similar to cookies
    • But not such a small limit
    • Not every browser supports it (may need polyfill)
  • Form/Post/Hidden/ViewState
    • You could just post the data and drag the information from response to response
    • But this gets really annoying with back buttons & timeouts
    • Lots of work, and again, the user can tamper with the information
like image 145
Matthew Groves Avatar answered Dec 12 '25 17:12

Matthew Groves



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!