I have an ajax form and inside i have an editor-for a model which has email Field with custom validation attribute which check if email already exist in the server so it goes like this:
$("#submitPop").live("click", (function (e) {
var form = $("#popForm");
form.validate();
if (form.valid()) {
$.ajax({
type: "POST",
url: "/Account/RegisterEmail/",
data: form.serialize(),
dataType: "json",
success: function (result) {
if (result.Status) {
location.reload(true);
} else {
alert("Something Went Wrong!"); //what should i write here to show the error message in its generated field-validation-error span
}
}
});
}
return false;
}));
inside the ajax form:
@Html.EditorFor(x => x.Email)
@Html.ValidationMessageFor(x => x.Email)</li>
as the comment says what do i when the ajax result return false in order to show the error message in the field-validation-error span generated?
i was thinking of a native way to inform jquery of the error and inform jquery to change all the needed changes like putting the red X and making the error span font red etc etc something like:
$.Validator.ShowErrorMessageFor("Email","Email is Already Taken")