0

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; }
}
4
  • If you put a breakpoint in your AjaxPostTypeUpload is it stopping there? Commented Jan 15, 2013 at 10:28
  • i didn't get you, what do you mean by stopping there? Commented Jan 15, 2013 at 10:31
  • By stopping there I mean, does the code stop at the breakpoint. Commented Jan 15, 2013 at 11:23
  • yes it is calling AjaxPostTypeUpload Commented Jan 15, 2013 at 11:29

1 Answer 1

2

Try just returning a basic object with the success parameter:

return new { message = "success" };
Sign up to request clarification or add additional context in comments.

2 Comments

ok works but not returning textarea in the response will not cause any problem? can you clarify?
I don't understand what you mean by 'not returning textarea in the response'? This is technically no different from what you were doing in your example, the only difference is the format of the JSON response.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.