MVC数据注释不等于 [英] MVC Data Annotation For Not Equal
本文介绍了MVC数据注释不等于的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
我有一个模型,其中有两个属性我需要比较,它们的属性不应该相等。
公共课客户
{
公共字符串NewPassword {get; set;}
public string OldPassword {get;设置;}
}
是否有任何可用的属性如下:不比较
谢谢
Hi Everybody,
I have a Model in which have Two Properties that i need to compare and they properties should not equal.
Public class Customer
{
public string NewPassword {get; set;}
public string OldPassword {get; set;}
}
Is there any attribute avalable for same like : Not Compare
Thanks
推荐答案
转到VS.
创建MVC应用程序类型的新项目 - >互联网应用程序。
然后转到Models文件夹并查看AccountModels。
你看到了吗? :
Go to VS.
Create new project of type MVC Application -> Internet Application.
Then go to Models folder and look at AccountModels.
Are you see this? :
[Required]
[StringLength(100, ErrorMessage = "Value {0} must be greater length than {2} symbols.", MinimumLength = 6)]
[DataType(DataType.Password)]
[Display(Name = "New password")]
public string NewPassword { get; set; }
[DataType(DataType.Password)]
[Display(Name = "Confirm Password")]
[Compare("NewPassword", ErrorMessage = "New Password and Confirm Password are not equal.")]
public string ConfirmPassword { get; set; }
您如何喜欢这个标准属性比较?
UPD:很抱歉第一次没有正确理解你。
How do you like this standart attribute "Compare"?
UPD: Sorry not properly understand you from first time.
这篇关于MVC数据注释不等于的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文