ASP.NET MVC3 How to Persist File Upload Data Across Multiple Requests Without Saving File to Disk
This question relates to ASP.N开发者_如何学PythonET MVC3 using the Razor Engine.
What I need to do:
Allow user to upload a comma delimted text file
On post, parse the file on the server (without saving to disk) and display a message to the user about the contents of the file in a different view.
Allow the user to choose "Yes" or "No" to perform a final import of the data within the file to some external database.
NOTE: I have no problem uploading the file or reading the contents of the file or any of the obvious steps involved there. The issue I have is that I don't know the best way to accomplish the data persistence between views using MVC3.
Thanks in advance for the help.
Once you parse the CSV file into a model you could store this model into the Session so that if the user chooses "Yes" you would fetch the model from the session and persist it to the database. If you don't want to store large quantities of data into the session you could always save the model into some temporary file on disk and store only the path to this temporary file into the Session so that you could retrieve it later.
The best non-disk persistent storage in ASP.net applications is the runtime cache.
see documentation here
精彩评论