The MVC application uploads files.

Source: Internet
Author: User

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:

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.