我有“JsonResult”类型的操作方法。我使用 ajax post 调用它。我想将操作方法中的自定义错误返回给 ajax post 并将这些错误显示为验证摘要。
[HttpPost]
public JsonResult RegisterUser(RegistrationModel model)
{
//if username already exists return custom error to be displayed on view
//under validation summary
// control should go back to error function with message to be displayed.
}
$.ajax({
url: url,
type: 'POST',
dataType: 'json',
data: ko.toJSON(model),
contentType: "application/json; charset=utf-8",
success: function (result) {
success(result)
},
error: function (req, status, error) {
error(req, status, error);
}
});
function success(result) {
//Do Something
}
function error(req, status, error) {
//Display error messages under validation summary.
}