javascript - Upload files from <input type="file" multiple/> via appending to FormData -
i have form file input
<input type="file" id="fileinput" multiple />
and try upload files server. server-side code this:
[httppost] public actionresult index(httppostedfilebase[] files) { ... process ... }
for send post request 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 doesn't work. if add name="files"
attribute input (for native bind) , remove instruction formdata.append("files", $('#fileinput')[0].files);
code works fine.
so difference between theese ways , how can pass files via appending data formdata?
note: in work can't bind form via name attribute, cause form comes template , have no name attribute.
Comments
Post a Comment