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?