Using HTML5 and asp.net mvc to upload multiple file implementation Code _ Practical skills

Source: Internet
Author: User

Copy Code code as follows:

<form action= "/home/upload" enctype= "Multipart/form-data" id= "Form2" method= "POST" >
<input type= "File" Name= "Filetoupload" id= "fileToUpload2" multiple= "multiple"/>
<input type= "Submit" value= "Submit"/>
</form>

That's what we can do in the ASP.net MVC Web application:
Copy Code code as follows:

@using (Html.BeginForm ("Upload", "Home", FormMethod.Post, new {enctype = "multipart/form-data", id = "Form2"}))
{
<label for= "File" >upload image:</label>
<input type= "File" Name= "Filetoupload" id= "fileToUpload2" multiple= "multiple"/>
<input type= "Submit" value= "Upload Image by Submit"/>
}

Suppose this is a homecontroller view that is about to be submitted to the upload action, looking at the following server-side code:
Copy Code code as follows:

[HttpPost]
Public ActionResult Upload (httppostedfilebase[] filetoupload)
{
foreach (httppostedfilebase file in filetoupload)
{
String path = System.IO.Path.Combine (Server.MapPath ("~/app_data"), System.IO.Path.GetFileName (file. FileName));
File. SaveAs (path);
}

Viewbag.message = "File (s) uploaded successfully";
Return redirecttoaction ("Index");
}

Okay, that's simple. Here we store the received file in the App_Data folder and return to the index action. Look at the picture below, we can select multiple pictures from the file selector:


About HTML5 This feature is supported in those browsers, you can go here to view. You can also view the official documents of the consortium. We'll test it out under Firefox 14.01.

You want to help with your web development.

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.