I have a form with file input
<input type="file" id="FileInput" multiple />
and I try to upload files to server. Server-side code like this:
[HttpPost]
public ActionResult Index(HttpPostedFileBase[] files) {
... process ...
}
For send post request I use $.ajax
var formData = new FormData($('#FormId')[
formData.append("files", $('#FileInput')[0].files);
$.ajax({
url: "/default/index",
type: "POST",
data: formData,
contentType: false,
processData: false,
success: function() {
alert("success");
}
});
and it doesn't work.
But if I add name="files"
attribute to input (for native bind) and remove instruction formData.append("files", $('#FileInput')[0].files);
code works fine.
So what difference between theese ways and how I can pass files via appending data to FormData?
NOTE: in my work I can't bind form via name attribute, cause the form comes from template and have no name attribute.