dotNetNewbie
dotNetNewbie

Reputation: 789

How to capture the return value from controller action

I am using uploadify to upload .csv files on my ASP.NET MVC app. From the controller action I return a JSON with a couple of values like this:

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

The following is the uploadify code:

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

I am trying to read the "message" that I returned from the controller action but can't figure out how. Please see the alerts above.The first alert returns: [object Object] and the second return null.

Upvotes: 1

Views: 1003

Answers (2)

Ishraq Ahmad
Ishraq Ahmad

Reputation: 1327

In old version of Uploadify onComplete event, use to provide response back from Controller. But, in latest version you need to use onUploadSuccess event, like this,

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

Upvotes: 0

Darin Dimitrov
Darin Dimitrov

Reputation: 1038930

Try like this:

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

Also don't put quotes around the event name.

Upvotes: 3

Related Questions