我正在使用 uploadify 在我的 ASP.NET MVC 应用程序上上传 .csv 文件。从 Controller 操作中,我返回一个带有几个值的 JSON,如下所示:
return Json(new { success = false, message = result.Message });
以下是上传代码:
$("#email").uploadify(
{
'uploader': '/js/component/uploadify/uploadify.swf',
'script': '/email/UploadEmail',
'cancelImg': '/js/component/uploadify/cancel.png',
'fileExt': '*.csv',
'fileDesc': '*.csv',
'auto': true,
'multi': false,
'buttonText': 'Upload...',
'onComplete': function (event, queueID, fileObj, response, data)
{
alert(jQuery.parseJSON(response));
alert(jQuery.parseJSON(response.message));
var filename = fileObj.name;
$('#emailSuppressionFile').append('<input id="' + queueID + '" type="hidden" name="files[' + queueID + ']" value="' + filename + '" />');
}
});
我正在尝试读取从 Controller 操作返回的“消息”,但不知道如何读取。请参阅上面的警报。第一个警报返回:[object Object],第二个警报返回 null。
最佳答案
尝试这样:
onComplete: function(event, queueID, fileObj, response, data) {
var json = jQuery.parseJSON(response);
alert(json.message);
},
也不要在事件名称两边加引号。
关于jquery - 如何捕获 Controller 操作的返回值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12693896/