Skip to content

Instantly share code, notes, and snippets.

@sphingu
Last active December 18, 2015 15:39
Show Gist options
  • Save sphingu/5805591 to your computer and use it in GitHub Desktop.
Save sphingu/5805591 to your computer and use it in GitHub Desktop.
Multiple File Upload in MVC
http://www.mindstick.com/Articles/518b07f7-3fc8-4b86-8ab9-cab49ecb001a/
//In View
<form action="@Url.Action("UploadPayment")" method="post" enctype="multipart/form-data">
<input type="file" name="FileUploads" id="FileUploads1" />
<input type="file" name="FileUploads" id="FileUploads2" />
//In Model
public IEnumerable<HttpPostedFileBase> FileUploads { get; set; }
//In Cotroller
[HttpPost]
public ActionResult UploadPayment(PaymentViewModel paymentVM)
{
IEnumerable<HttpPostedFileBase> files = paymentVM.FileUploads;
foreach (HttpPostedFileBase file in files)
{
if (file != null && file.ContentType.Length != 0)
{
byte[] fileBytes = new byte[file.ContentLength];
file.InputStream.Read(fileBytes, 0, file.ContentLength);
//Code For Storing Binary File to database....
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment