用ajaxFileUpload时,MVC的Controller层,不能用JSON去返回数据,因为前台会接不到
返回信息不能用json(),而是要转换一下。 return Content(JsonHelper.Serializer(res));
function singleUpload() { if (!$(‘#singleFile’).val()) { alert(‘请选择需要上传的文件!’); return false; } var url = ‘@Url.Action(“UplpadMailAttachment”)’;
$.ajaxFileUpload({ type: ‘POST’, url: url, secureuri: false, fileElementId: ‘singleFile’, //文件选择框的name属性 dataType: ‘json’, //服务器返回的格式 xml,script,json,html success: function (data, status) //相当于java中try语句块的用法 { if (data.IsSuccess) { alert(data.Message); $(“#hfVisaAttachmentPath”).val(data.Message); } else { alert(data.Message); }
}, error: function (data, status, e) //相当于java中catch语句块的用法 { console.log(data); console.log(status); console.log(e); alert(e); } }); }来自为知笔记(Wiz)