Copy codeThe Code is 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>
In Asp.net MVC web application, we can achieve this:
Copy codeThe Code is 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"/>
}
Assume that this is a View under HomeController, which is about to be submitted to the Upload Action. Check the following server code:
Copy codeThe Code is 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 then return the Action of the Index. See the following picture. We can select multiple images from the file selector:
You can check the HTML5 feature in those browsers. You can also view the W3C official documentation. We can pass the test in FireFox 14.01.
Hope to help your Web development.