is there a good example of how to upload multiple image files in asp.net mvc? I know we can use HttpPostedFileBase to upload one file. Is there a way to upload multiple file
Use this jQuery plugin
just include plugin js files, create tag:
(Except IE9 it is not allowing select multiple files in select dialog)
Add some JavaScript:
$(function () {
$('#fileUpload').fileupload({
dataType: 'json',
done: function (e, data) {
$.each(data.result.files, function (index, file) {
$('').text(file.name).appendTo(document.body);
});
}
});
});
In controller action just check Request.Files and do whatever you want. Here is a good documentation
[HttpPost]
public JsonResult Upload()
{
foreach (var file in Request.Files)
{
if(file.ContentLength > 0)
{
file.SaveAs(Server.MapPath("~/Upload/" + file.FileName));
}
}
return Json(new { result = true });
}