1

I'm using an ajax form with this initialization on the view:

@using (Ajax.BeginForm("EditUser", "Admin", new AjaxOptions()
{
    HttpMethod = "POST",
    OnSuccess = "AddEditSuccessul",
    OnFailure = "AddEditFailed",
    OnBegin = "HideModalEditUser"
}, new { @id = "MainForm" }))

And it works quite well. I would like to add a message to the AddEditFailed to warn the user about why the operation failed. I tried to edit the code to:

OnFailure = "AddEditFailed(message)",

And put return new HttpStatusCodeResult(code, "Custom message."); in the controller. I also adapted the JS to:

function AddEditFailed(message)
{
    swal({
        title: "Error",
        text: "Details : " + message,
        type: "error",
        showCancelButton: false,
        confirmButtonColor: "#DD6B55",
        confirmButtonText: "OK",
        closeOnConfirm: true
    });
}

But I get the error:

ReferenceError: message is not defined

Is there a way to do it without changing the whole mechanism or am I in the obligation to refactor the process?

1 Answer 1

3

The signature for the function is OnFailure(xhr, status, error). It is strange that message is undefined. There should be your xhr request.

Oh it seems that you should change your code to
OnFailure = "AddEditFailed(xhr, status, 'Person')"
Check out this post

Sign up to request clarification or add additional context in comments.

1 Comment

Beat me by a few seconds!

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.