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.