This question already has answers here:
</div>
</div>
<div class="grid--cell mb0 mt4">
<a href="/questions/2320069/jquery-ajax-file-upload" dir="ltr">jQuery Ajax File Upload</a>
<span class="question-originals-answer-count">
(24 answers)
</span>
</div>
<div class="grid--cell mb0 mt4">
<a href="/questions/29293637/how-to-append-whole-set-of-model-to-formdata-and-obtain-it-in-mvc" dir="ltr">How to append whole set of model to formdata and obtain it in MVC</a>
<span class="question-originals-answer-count">
(3 answers)
</span>
</div>
<div class="grid--cell mb0 mt8">Closed <span title="2017-10-06 21:48:47Z" class="relativetime">2 years ago</span>.</div>
</div>
</aside>
I need to upload multiple files along with other 2D Arrays. my code is below, but which is not woking. when i remove the file upload or the array data(addProcurementModel ) from code then it is working fine.
JS
var fileUpload = $("#flpFileType1").get(0);
var files = fileUpload.files;
var fileData = new FormData();
for (var i = 0; i < files.length; i++) {
fileData.append(files[i].name, files[i]);
}
var addProcurementModel = {
Suppliers: suppliers,
ItemSpecifications: itemSpecifications,
PurchaseJustification: purchaseJustification
};
$.ajax({
type: "POST",
url: "/Procurement/AddProcurement",
data: { AddProcurementModel: addProcurementModel, FileData: fileData },
cache: false,
processData: false,
dataType: 'json',
contentType: false,
success: function (sucess) {
if(sucess.message==true)
{
//do something
}
}
});
Controller
[HttpPost]
public ActionResult AddProcurement(AddProcurementModel addProcurementModel)
{
HttpFileCollectionBase files = Request.Files;
foreach (string file in files)
{
var fileContent = Request.Files[file];
}
}
</div>