Tag: attributeusage

使用AttributeTargets.Class对自定义ValidationAttribute进行客户端validation

是否可以为Class范围中使用的自定义ValidationAttribute实现客户端站点validation? 例如我的MaxLengthGlobal,它应该确保所有输入字段的全局最大限制。 [AttributeUsage(AttributeTargets.Class)] public class MaxLengthGlobalAttribute : ValidationAttribute, IClientValidatable { public int MaximumLength { get; private set; } public MaxLengthGlobalAttribute(int maximumLength) { this.MaximumLength = maximumLength; } public override bool IsValid(object value) { var properties = TypeDescriptor.GetProperties(value); foreach (PropertyDescriptor property in properties) { var stringValue = property.GetValue(value) as string; if (stringValue != null && (stringValue.Length > […]