Validation does not work when I use Validator.TryValidateObject.
Posted
by ashraf
on Stack Overflow
See other posts from Stack Overflow
or by ashraf
Published on 2010-03-11T01:53:30Z
Indexed on
2010/03/11
19:34 UTC
Read the original article
Hit count: 801
DataAnnotations does not work with buddy class. The following code always validate true. Why ?
var isValid = Validator.TryValidateObject(new Customer(), Context, results, true);
and here is the buddy class.
public partial class Customer
{
public string Name { get; set; }
public int Age { get; set; }
}
[MetadataType(typeof(CustomerMetaData))]
public partial class Customer
{
public class CustomerMetaData
{
[Required(ErrorMessage = "You must supply a name for a customer.")]
public string Name { get; set; }
}
}
Here is another thread with same question., but no answer. link text
© Stack Overflow or respective owner