我正在使用http://aquantum-demo.appspot.com/file-upload将文件上传到我的网站。
文件在 Firefox 和 Chrome 中上传正常,但当我尝试从 IE 9 上传时 Controller 操作中的文件参数为空。 有什么想法吗?
提前致谢。
这是我的 Controller 操作:
[HttpPost]
public JsonResult UploadFile(HttpPostedFileBase file, FormCollection collection)
{
var model = newObject();
TryUpdateModel(model);
model.ID = saveDocObject(model);
Guid fileid = saveUploadedFile(model.ID, file);
return Json(new { name = file.FileName, fid = fileid.ToString() });
}
这是我的观点:
<div id="upload_files">
<div id = "filediv">
<input type="file" name="file" class="green"/>
<button>Upload</button>
<div>Upload it</div>
</div>
</div>
<table id="files" width="200px">
</table>
最后是我的 jquery:
$('#upload_files').fileUpload({
url: '/Document/UploadFile',
method: 'POST',
uploadTable: $('#files'),
downloadTable: $('#files')
});
最佳答案
必须在我的 View 表单中添加 enctype = "multipart/form-data"
。
现在文件上传正常,但之后 IE 会尝试保存响应。
因此,在 Controller 方法中,我将 content-type
更改为 "text/plain"
现在
一切正常。
关于jquery - Blueimp Jquery-File-Upload 通过 IE 9 在 MVC Controller 中提交空文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7675644/