I have to check to see if the new users email already exists in the database. The email passes all the normal validation but what if I want to trigger a special validation from the controller if the email already exists after checking it against the database?
In controller:
ModelState.AddModelError("ErrorEmail", "Error Message");
In View:
@Html.ValidationMessage("ErrorEmail")
Hope this helps
I think what you are looking for is the RemoteAttribute
.
This is a ValidationAttribute for remote validation. It works like the other validation attributes by adding model errors to your modelstate dictionary.
Check out these articles on using the RemoteAttribute
:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With