gpt4 book ai didi

c# - .net 中 [compare ("")] 数据注释的对面?

转载 作者:可可西里 更新时间:2023-11-01 07:56:10 25 4
gpt4 key购买 nike

ASP.NET 中 [Compare("")] data annotation"的相反/否定是什么?

即:两个属性必须具有不同的值。

public string UserName { get; set; }

[Something["UserName"]]
public string Password { get; set; }

最佳答案

您可以使用 MVC Foolproof Validation 中包含的 [NotEqualTo] 数据注释运算符.我现在就在用它,效果很好!

MVC Foolproof 是由 @nick-riggs 创建的开源库并且有很多可用的验证器。除了进行服务器端验证外,它还进行客户端非侵入式验证。

开箱即用的内置验证器的完整列表:

包含的运算符验证器

[Is]
[EqualTo]
[NotEqualTo]
[GreaterThan]
[LessThan]
[GreaterThanOrEqualTo]
[LessThanOrEqualTo]

包含必需的验证器

[RequiredIf]
[RequiredIfNot]
[RequiredIfTrue]
[RequiredIfFalse]
[RequiredIfEmpty]
[RequiredIfNotEmpty]
[RequiredIfRegExMatch]
[RequiredIfNotRegExMatch]

关于c# - .net 中 [compare ("")] 数据注释的对面?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8786251/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com