我在尝试使用jquery和Asp MVC上传zip文件时遇到了一些问题。
只要我选择单个文本,img,bin或任何其他单个文件,我的上传工作正常,但当我尝试上传zip时,我会在Controller调用中获得404
[HttpPost]
public ActionResult UploadFiles()
{
for (int i = 0; i < Request.Files.Count; i++)
{
var file = Request.Files[i];
var fileName = Path.GetFileName(file.FileName);
}
return Json("success", JsonRequestBehavior.AllowGet);
}
$(document).ready(function () {
$('#btnUpload').click(function () {
// Checking whether FormData is available in browser
if (window.FormData !== undefined) {
var fileUpload = $("#FileUpload").get(0);
var files = fileUpload.files;
// Create FormData object
var fileData = new FormData();
// Looping over all files and add it to FormData object
for (var i = 0; i < files.length; i++) {
fileData.append(files[i].name, files[i]);
}
$.ajax({
url: '/File/UploadFiles',
type: "POST",
contentType: false, // Not to set any content header
processData: false, // Not to process data
data: fileData,
success: function (result) {
alert(result);
},
error: function (err) {
alert(err.statusText);
}
});
} else {
alert("FormData is not supported.");
}
});
});
&#13;
答案 0 :(得分:0)
请在webconfig文件的配置标记中添加上传的文件大小以避免此问题。 默认是30MB。
<configuration>
<system.web>
<httpRuntime maxRequestLength="size in bytes/maxAllowedContentLength" />
</system.web>
</configuration>