在mvc应用程序中上传Ajax文件

在我的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 Host:localhost:55538 User-Agent: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 Content-Type:multipart / form-data; boundary = --------------------------- 481414423196 Content-Length:6046387

----------------------------- 481414423196 Content-Disposition:form-data; NAME = “photoDescription”

----------------------------- 481414423196 Content-Disposition:form-data; NAME = “idPhotoFolder”

136 ----------------------------- 481414423196 Content-Disposition:form-data; 命名=一个 “UploadFile”; filename =“sam_1103.jpg”Content-Type:image / jpeg

HTTP / 1.1 504 Fiddler - 接收失败内容类型:text / html; charset = UTF-8连接:关闭时间戳:15:30:34.321

[Fiddler] ReadResponse()失败:服务器没有为此请求返回响应。

一些想法在哪里是问题?

谢谢


看起来服务器没有响应(Http 504)。

ProcessPhoto方法是否被调用?

如果没有,那么你应该看看你的.config设置。 您也可以在没有启用fiddler的情况下检查ajax onComplete方法中的服务器响应。

如果您的服务器ProcessPhoto方法确实被调用,则在本地Web服务器和远程Web服务器上都会发生错误(消除任何其他可能的超时来源会很好)。

最后,如果你的方法被调用,它可能是你的照片处理,而不是实际上很慢的Web服务器通信? 最后一个将是我的初步猜测,但对于更多信息会更好:-)

无论如何,只是一些想法:-)

链接地址: http://www.djcxy.com/p/46477.html

上一篇: Ajax file upload in mvc application

下一篇: uploadify queueData error