DataAnnotation来比较两个属性 [英] DataAnnotation to compare two properties

查看:248
本文介绍了DataAnnotation来比较两个属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法用数据说明比较两个表单字段(如确认的电子邮件地址)是相同的,允许贴在表格前的?

Is there any way of using data annotations to compare two form field (eg. to confirm an email address) are the same, before allowing the form to be posted?

如。可以定期EX pression数据标注使用匹配函数引用另一个属性在视图模型?

eg. can the regular expression data annotation use the match function to reference another property in a ViewModel?

推荐答案

使用的<一个href="http://msdn.microsoft.com/en-us/library/system.componentmodel.dataannotations.compareattribute%28v=vs.110%29.aspx">CompareAttribute

public string EmailAddress {get; set;}

[CompareAttribute("EmailAddress", ErrorMessage = "Emails mismatch")]
public string VerifiedEmailAddress { get; set; }

这篇关于DataAnnotation来比较两个属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆