Last active
December 18, 2015 15:39
-
-
Save sphingu/5805591 to your computer and use it in GitHub Desktop.
Multiple File Upload in MVC
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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