I am trying to pass multiple pdf files to the controller method. This is my code in javascript:
var formData = new FormData();
formData.append("data", JSON.stringify(data));
formData.append("httpPostedFileBase", file1, "ff2.pdf");
formData.append("httpPostedFileBase", file1, "ff1.pdf");
$.ajax({
type: "POST",
url: "@Url.Action("GetFiles", "FileUpload")",
data: formData,
dataType: 'json',
contentType: false,
processData: false,
success: function () {
console.log("5");
},
error: function () {
alert('Failure to send request');
}
});
And this is in the controller:
public ActionResult GetFiles(HttpPostedFileBase[] httpPostedFileBase, string data) {
try {
if (Request.Files.Count > 0) {
//...
I get a "Failure to send request" alert right away:
It does not even reach the controller method.
However, works fine if I only try to append a single file. The funny thing is that I've written this functionality in a different project and it works well there.
I tried passing an array of blobs instead of appending them one by one to formData but that did not work either. Any help would be appreciated.