Since learning MVC, I have always wanted to implement the file upload function. jQuery is used for file upload. There are many plug-ins. In this demonstration, Insus. NET uses Uploadify. Bytes /.
You can use the NuGet Packages manager of MVC to install the jQuery plug-in:
After installation, you can see it in the Scripts directory of the MVC application:
In HomeContollers, create an ActionResult and a ContentResult action. The former creates a view for MVC and the latter processes file uploads.
In the demo, Insus. NET stores the uploaded files in the Temp directory of the MVC application. Of course, you can store the files in the directory you specified or in the database.
#1 ~ #3 reference the js libraries and styles of jQuery and Uploadify in the Head node of the view.
#4 is the uploaded html Tag.
For details about #5, refer to the following jQuery code:
Finally, let's look at the real-time demonstration results: