我在视图上使用ajax表单进行初始化:
@using (Ajax.BeginForm("EditUser", "Admin", new AjaxOptions()
{
HttpMethod = "POST",
OnSuccess = "AddEditSuccessul",
OnFailure = "AddEditFailed",
OnBegin = "HideModalEditUser"
}, new { @id = "MainForm" }))
它运作良好。我想向AddEditFailed
添加一条消息,警告用户操作失败的原因。我尝试将代码编辑为:
OnFailure = "AddEditFailed(message)",
并将return new HttpStatusCodeResult(code, "Custom message.");
放入控制器中。我还将JS改编为:
function AddEditFailed(message)
{
swal({
title: "Error",
text: "Details : " + message,
type: "error",
showCancelButton: false,
confirmButtonColor: "#DD6B55",
confirmButtonText: "OK",
closeOnConfirm: true
});
}
但我收到错误:
ReferenceError:未定义消息
有没有办法在不改变整个机制的情况下做到这一点,还是我有义务重构这个过程?
答案 0 :(得分:2)
该功能的签名是OnFailure(xhr,status,error)。 奇怪的是,消息未定义。应该有你的xhr请求。
哦,您似乎应该将代码更改为
{"A":{"x":<!-- ?A.x -->},"B":{"x":<!-- ?B.x -->}}
查看this post