Bac*_*Dao 5 c# asp.net arrays asp.net-mvc data-annotations
我有一个属性:
[MaxLength(3)]
public string State { get; set; }
Run Code Online (Sandbox Code Playgroud)
在指定的属性上State,我只希望它匹配给定的 5 个澳大利亚州:
{ "VIC", "NSW", "QLD", "SA", "TAS", "WA" }。我如何在这种情况下使用 DataAnnotations?
您可以使用正则表达式属性
[RegularExpression("VIC|NSW|QLD|TAS|WA|SA")]
[MaxLength(3)]
public string State { get; set; }
Run Code Online (Sandbox Code Playgroud)
只允许维多利亚州、新南威尔士州、昆士兰州、塔斯马尼亚州、西澳州或南澳州