Given the following object,
public class Question
{
[Required]
public string QuestionText { get; set; }
[Range(1, 5)]
public int Difficulty { get; set; }
}
With the following Validation Code
ICollection<ValidationResult> results = new List<ValidationResult>();
Question question = new Question();
ValidationContext ctx = new ValidationContext(question, null, null);
Validator.TryValidateObject(question, ctx, results);
// results.Length = 1
Why does Range attribute not create a validation error when Required does (the value is 0 obviously)?