MVC 3 Razor - Trigger validation from controller
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
:
- http://deanhume.com/Home/BlogPost/mvc-3-and-remote-validation/51
- http://davidhayden.com/blog/dave/archive/2011/01/04/ASPNETMVC3RemoteValidationTutorial.aspx
In controller:
ModelState.AddModelError("ErrorEmail", "Error Message");
In View:
@Html.ValidationMessage("ErrorEmail")
Hope this helps