开发者

MVC Form Validation

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!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜