2012-10-02 59 views
1

我正在使用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。

回答

3

嘗試這樣的:

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

也不要把周圍的事件名稱引號。

+0

感謝您的答覆。我試過了,但結果仍然返回null。 – dotNetNewbie

+0

'response.responseText'的價值是什麼? –

+0

response.responseText未定義,結果然後計算爲null。 – dotNetNewbie

0

在舊版本的Uploadify onComplete事件中,用於提供Controller的響應。 不過,在最新的版本中,你需要使用onUploadSuccess事件,這樣,

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