Hi.
I used your 'TestProject' sample code from the codeproject page and let the HomeViewModel implement IValidatableObject, to do some extra checks. For instance: object-level validation, or a call to the database.
But the Validate() method of IValidatableObject is never called.
Is there a way to let the Validation method be called?
The viewmodel code:
public class HomeViewModel : IValidatableObject
{
[Required()]
[StringLength(40)]
public string Name { get; set; }
[Required, Compare("Name", ErrorMessage = "Ange messy")]
public int Age { get; set; }
public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
{
//this is never called
var errors = new List<ValidationResult>();
if (nameIsNotUniqueInDatabase(Name))
errors.Add(new ValidationResult(LocalizedErrors.NameIsNotUnique));
return errors;
}
private bool nameIsNotUniqueInDatabase(string name)
{
//call to the database...
return false;
}
}
Hi. I used your 'TestProject' sample code from the codeproject page and let the HomeViewModel implement IValidatableObject, to do some extra checks. For instance: object-level validation, or a call to the database. But the Validate() method of IValidatableObject is never called.
Is there a way to let the Validation method be called?
The viewmodel code:
Thanks! Anna