I have a form that I would like to validate that a field exist in a database. I am currently validating that all fields are in the correct text format etc and posting them to the controller.
The problem being that should the field not exist in the database I am returning the view but the post data is being lost from the form and I am also unaware of how to throw a nice error message explaining what has just happened.
Would anyone know of nice method for preforming some validation on form data within th开发者_开发技巧e controller and throwing exceptions messages all while maintaining the form data in the form?
Solve this by simply adding errors to the modelstate stack:
ModelState.AddModelError("_FORM", "The new password and confirmation password do not match.");
Simples!
精彩评论