I have Action Method of types "JsonResult". I call it using ajax post. I want to return the custom errors from the action method back to ajax post and display those errors as validation Summary.
[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.
}