在我的 MVC 应用程序中,我在这部分代码中使用了 Ajax 上传(版本 3.5 (23.06.2009)):
<div id="userPhotosUpload">
<span class="tabs_fieldDesc">@Html.Label("txtPhotoDescription", "Desc")</span>
@Html.TextBox("txtPhotoDescription", "", new { @maxlength = "30", @class = "tabs_fullLength" })
<div class="buttonLine">
<button id="btnAddUserPhoto">Add picture</button>
</div>
<input id="txtSelectedPhotoFolderId" type="hidden" value="" />
</div>
<script type="text/javascript">
$(document).ready(function () {
//photo upload
var photoUpload = new AjaxUpload($('#btnAddUserPhoto'), {
action: '/Profile/ProcessPhoto',
name: 'uploadfile',
responseType: 'json',
autoSubmit: true,
onSubmit: function (file, ext) {
showProgressBar();
photoUpload.setData({
photoDescription: $('#txtPhotoDescription').val(),
idPhotoFolder: $('#txtSelectedPhotoFolderId').val()
});
},
onComplete: function (file, response) {
hideProgressBar();
$('#txtPhotoDescription').val('');
var currentSelectedFolderId = getSelectedFolder();
LoadPhotoFolders();
SelectPhotoFolder(currentSelectedFolderId);
}
});
</script>
如果我上传大于 1MB 的文件,AjaxUpload 不会在控制器中调用方法:
[Authorize]
[HttpPost]
[AcceptVerbs(HttpVerbs.Post)]
[ValidateInput(false)]
public JsonResult ProcessPhoto(string photoDescription, Int64 idPhotoFolder)
{
//process request with file
}
和Fiddler2给我看这个:
POST /Profile/AddUserPhoto HTTP/1.1 主机:localhost:55538 用户代理:Mozilla/5.0 (Windows NT 6.1; WOW64; rv:15.0) Gecko/20100101 Firefox/15.0 Accept: text/html,application/xhtml+xml,application /xml;q=0.9,/ _;q=0.8 Accept-Language: cs,en-us;q=0.7,en;q=0.3 Accept-Encoding: gzip, deflate Connection: keep-alive Referer: Cookie: AspxAutoDetectCookieSupport=1; .ASPXAUTH = AB45C67E90AD19402C47818CC4BC78504C96F6BB063E07F89E918F22D3A42B441B14B57818448BAAD3ABEEED48C1EA41431C89F149B3BA53D59950694F33C447462EE56AC33CFB54F1ADAC7B7A4F5D69F6ED3855A649F217EDC56B2250E6BFC87052C0640C1C191F212A76B3A9D9973609F6E537992BBADBC1A3F97853A8B90485DE9C11819D54D1F0D0F9838EDAE73E; ASP.NET_SessionId=gflyfmea2ty2gm3i4rea2adx 内容类型:multipart/form-data;边界=---------------481414423196 内容长度:6046387
--------------------------481414423196 内容处置:表单数据;名称="照片描述"
--------------------------481414423196 内容处置:表单数据;名称="idPhotoFolder"
136 -----------------481414423196 内容处置:表单数据;名称="上传文件"; 文件名="sam_1103.jpg" 内容类型:图像/jpeg
HTTP/1.1 504 Fiddler - 接收失败 Content-Type: text/html; charset=UTF-8 连接:关闭时间戳:15:30:34.321
[Fiddler] ReadResponse() 失败:服务器没有返回对此请求的响应。
一些想法哪里有问题?
谢谢