0
我想設置一些使用System.ComponentModel.DataAnnotations的自定義驗證方法。我已經編寫了一些用於驗證的通用方法。這裏是問題發生的地方:無法驗證屬性
private void SetValidationAttributeErrors<TEntity>(TEntity item, List<string> errors)
{
var result = from prop in TypeDescriptor.GetProperties(item).Cast<PropertyDescriptor>()
from attribute in prop.Attributes.OfType<ValidationAttribute>()
where !attribute.IsValid(prop.GetValue(item))
select attribute.FormatErrorMessage(string.Empty);
}
我在'ValidationAttribute'類型上有一個錯誤,說它找不到。我有DataAnnotations的使用聲明。有任何想法嗎?
試着看着前面的stackoverflow發佈我認爲別人有問題/類似的問題http://stackoverflow.com/questions/2649581/custom-validationattribute-test-against-whole-model – MethodMan 2013-03-18 21:51:58