MVC3验证归因于断裂
-
16-10-2019 - |
题
我将项目从MVC2升级为MVC3,所有自定义验证属性都破裂了。在模型粘合剂阶段的某个时刻,它引发了以下异常:
Exception Details: System.ArgumentNullException: Value cannot be null.
Parameter name: value
System.ComponentModel.DataAnnotations.ValidationContext.set_DisplayName(String value)
我无法弄清楚哪些更改...没有DisplayName ..
我怀疑伊斯瓦利德替代,据说它以某种方式改变了,但签名是相同的。
public override bool IsValid(object value)
{
....
}
更多信息:
它显然会影响“ attributetargets.class”属性,如:
[AttributeUsage(AttributeTargets.Class, AllowMultiple = true, Inherited = true)]
public sealed class MyValidationAttribute : ValidationAttribute {}
解决方案
解决方案是将attributetargets.class更改为attributetargets.property,并重写每个验证器以使用给定的属性。
不隶属于 StackOverflow