执行远程验证后调用函数
我有具有此属性的模型:
[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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
奥列格,
我只使用过远程验证来验证唯一的用户名等,因此无法就您的特定问题提供任何经验丰富的建议,但是,以下链接“可能”有助于制定策略:
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..