I’m wondering. If I have a form that is broken up into steps where I allow users to upload various files, can I keep those files in TempData as binary data?
I need to be able to Save the file to disk, as well as save it to a database.
I have a single index.cshtml for a ViewModel that on each post, displays an editor for a property of the ViewModel that is of type IStepViewModel So each step represents a portion of the total data to be collected.
This way I can have 1 index.cshtml page to manage, and as many steps as I want.
The client wants some steps to allow uploads, and others won’t. They also want the uploads to be Ajaxy, which means posting while a step may be incomplete.
I want to be able to on the last review step, let them know here are the files you are thinking about uploading…Until they click the final TRANSMIT the files are in TempData, This way I think I can have a single atomic operation.
The operation would
– Save all the form data once again to DB
– Mark the database record with a bit flag of transmitted
– Save the files onto our server
Maybe there is a completely different approach I should be taking…If so, please let me know.
TempData uses session store to store data, thus anything that can be serialized can be saved there.
However, in your case, saving files in session store is probably not a good idea as you can easily run out of memory.
A solution would be used a tempfile based storage (you can even implement a temp db/file based session store.
This would avoid multiple trips to DB and unnecesary I/O on DB.
You can also make SQL Server as the backing store of your session or some other DB (oracle) that persists temp data. This way, your app deals with TempData and is agnostic of how the temp files are stored.