maztt
maztt

Reputation: 12304

asp.net mvc jquery form upload

I am using jQuery form up to upload the file but am unable to return any message from the controller. Am I doing it right below?

$(function() {
    $('#fileUploadForm').ajaxForm({               
        type: "POST",
        dataType: "json",             
        beforeSubmit: ShowRequest,
        success: SubmitSuccesful,
        error: AjaxError                               
    });                                    
});   

function ShowRequest(formData, jqForm, options) {
    var queryString = $.param(formData);
    return true;
}

function AjaxError() {
    $("#msgs").html("A file upload error occured.");
}

function SubmitSuccesful(responseText, statusText) {
    $("#fileUploadForm").unblock();
    $.growlUI(null, responseText.message);
}    
public FileUploadJsonResult AjaxPostTypeUpload(HttpPostedFileBase postedFile)
{
    try
    {
        string mess = string.Empty;          
        mess = "success";              
        return new FileUploadJsonResult { Data = new { message = mess }};
    }
    catch { throw; }
}

Upvotes: 0

Views: 221

Answers (1)

Rory McCrossan
Rory McCrossan

Reputation: 337714

Try just returning a basic object with the success parameter:

return new { message = "success" };

Upvotes: 2

Related Questions