That Bootstrap-fileinput was used on the first project.
This two weeks to do a short-term project, there are upload requirements, but I do not want to use the Bootstrap-fileinput, think on a button, do not need any style, and do not need any function.
So he used the XMLHttpRequest.
functionSaveFile (ID) {varFilecontroller = ' @Url. Action ("AddAttachment", "sitedeclare") ' + '? name=attr&id= ' +ID; varform =NewFormData (); for(vari = 0; I < Document.getelementsbyname ("btn-selectfileattr"). Length; i++) {form.append ("File" + I, Document.getelementsbyname ("btn-selectfileattr") [I].files[0]); } varXHR =NewXMLHttpRequest (); Xhr.open ("Post", Filecontroller,false); Xhr.onload=function(data) {if(Data.currentTarget.status = = "200") { if(Data.currentTarget.responseText! =NULL) { *****
} } Else { } }; Xhr.send (form); }
The code should be very clear, this is a multi-file upload Xhr.open ("post", Filecontroller, False); This false is synchronous, true is asynchronous.
This time it is to synchronize so it is changed to false, usually I am true.
Backstage is
foreach (string in request.files) { var as httppostedfilebase;
******}
That's almost it.
Uploading using XMLHttpRequest