执行远程验证后调用函数

发布于 2025-01-04 18:22:06 字数 520 浏览 0 评论 0原文

我有具有此属性的模型:

 [Required]
 [DataType(DataType.EmailAddress)]     
 [RegularExpression(@"^[\w!#$%&'*+\-/=?\^_`{|}~]+(\.[\w!#$%&'*+\-/=?\^_`{|}~]+)*@((([\-\w]+\.)+[a-zA-Z]{2,4})|(([0-9]{1,3}\.){3}[0-9]{1,3}))$",
        ErrorMessage = "Email has to be in correct format")]
 [Remote("UserRegistered", "User", ErrorMessage="This email is not registered")]
 public string Email { get; set; }

我想在远程验证返回错误后在视图中显示 div,但不在任何其他验证返回错误后显示 div。我可以在 asp.net mvc 3 & 中完成此操作吗?不引人注目的验证?

I have model with this property:

 [Required]
 [DataType(DataType.EmailAddress)]     
 [RegularExpression(@"^[\w!#$%&'*+\-/=?\^_`{|}~]+(\.[\w!#$%&'*+\-/=?\^_`{|}~]+)*@((([\-\w]+\.)+[a-zA-Z]{2,4})|(([0-9]{1,3}\.){3}[0-9]{1,3}))$",
        ErrorMessage = "Email has to be in correct format")]
 [Remote("UserRegistered", "User", ErrorMessage="This email is not registered")]
 public string Email { get; set; }

I want to show div in view after remote validation returns error, but not after any other validation returns error. Can i accomplish this in asp.net mvc 3 & unobtrusive validation?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

蓝天白云 2025-01-11 18:22:06

奥列格,

我只使用过远程验证来验证唯一的用户名等,因此无法就您的特定问题提供任何经验丰富的建议,但是,以下链接“可能”有助于制定策略:

http://msdn.microsoft.com/en-us/library/gg508808%28VS.98%29.aspx

也许更有用-> (提示使用远程验证的AdditionalFields属性):

http://edspencer.me.uk/2011/07/19/using-asp-net-mvc-remote-validation-the-real-world-additionalfields/

http://www.tugberkugurlu.com/archive/asp-net-mvc-remote-validation-for-multiple-fields-with-additionalfields-property

干杯..

Oleg,

I've only ever used remote validation for validating unique usernames etc, so can't give any experienced advice on your particular issue, however, the following link 'may' help figure a strategy:

http://msdn.microsoft.com/en-us/library/gg508808%28VS.98%29.aspx

perhaps more useful-> (hints at using the AdditionalFields property of Remote validation):

http://edspencer.me.uk/2011/07/19/using-asp-net-mvc-remote-validation-the-real-world-additionalfields/

http://www.tugberkugurlu.com/archive/asp-net-mvc-remote-validation-for-multiple-fields-with-additionalfields-property

cheers..

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文