MVC 3剃须刀 - 从控制器触发验证 [英] MVC 3 Razor - Trigger validation from controller
本文介绍了MVC 3剃须刀 - 从控制器触发验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我要检查,看看是否新用户的电子邮件数据库中已经存在。如果我想从控制器触发特殊的验证,如果检查电子邮件对数据库后已经存在的电子邮件通过了所有正常验证,但什么?
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?
推荐答案
在控制器: ModelState.AddModelError(ErrorEmail,错误消息);
在查看: @ Html.ValidationMessage(ErrorEmail)
希望这有助于
这篇关于MVC 3剃须刀 - 从控制器触发验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文