繁体   English   中英

如何从控制器操作中捕获返回值

[英]How to capture the return value from controller action

我使用uploadify在我的ASP.NET MVC应用程序上上传.csv文件。 从控制器操作我返回一个带有几个值的JSON,如下所示:

return Json(new { success = false, message = result.Message });

以下是uploadify代码:

$("#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 + '" />');                                   
}                                
                    });

我试图读取我从控制器操作返回的“消息”,但无法弄清楚如何。 请参阅上面的警报。第一个警报返回:[object Object],第二个返回null。

试试这样:

onComplete: function(event, queueID, fileObj, response, data) {
    var json = jQuery.parseJSON(response);
    alert(json.message);
},

也不要在事件名称周围加上引号。

在旧版本的Uploadify onComplete事件中,用于从Controller提供响应。 但是,在最新版本中,您需要使用onUploadSuccess事件,如下所示,

   'onUploadSuccess' : function(file, data, response) {
         alert('The file ' + file.name + ' was successfully uploaded with a response of ' + response + ':' + data);
    }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM