var formdata;
formdata = new FormData();
var fileInput = document.getElementById('fileToUploadinproposal');
//Iterating through each files selected in fileInput
for (i = 0; i < fileInput.fi.length; i++) {
//Appending each file to FormData object
formdata.append(fileInput.files[i].name, fileInput.files[i]);
}
//Creating an XMLHttpRequest and sending
var xhr = new XMLHttpRequest();
xhr.open('POST', "/Contract/UploadProposalDocument/");
xhr.send("");
xhr.onreadystatechange = function () {
debugger;
if (xhr.readyState == 4 && xhr.status == 200) {
$("#fileToUploadinproposal").val("")
alert(xhr.responseText);
}
}
return false;
客户端formdata中的不接受,fileInput.files.length也不接受
答案 0 :(得分:1)
您可以使用此jquery插件,因为我主要使用此asp.net mvc通过ajax上传文件:
http://powerdotnetcore.com/asp-net-mvc/asp-net-mvc-simple-ajax-file-upload-using-jquery
或者您可以参考我在本教程中制作并在某些情况下使用它,它使用iframe上传文件:
http://developmentpassion.blogspot.com/2013/08/aspnet-mvc-ajax-file-uploading-using.html