0

I have following object

public class TestClass
{
    [Required]
    public int TestId { get; set; }
}

I validate using:

List<ValidationResult> results = new List<ValidationResult>();
var vc = new ValidationContext(data);
if (Validator.TryValidateObject(data, vc, results, true))
    return;

This validates perfectly fine if data is of type TestClass but not when I pass list of TestClass items (List<TestClass>)

How can I validate the items withing a list without iterating?

Mighty Badaboom
  • 5,854
  • 5
  • 29
  • 50
pantonis
  • 4,526
  • 7
  • 46
  • 90

1 Answers1

0

TryValidateObject expects an object and not a list of. You have to write a helper class. Furthermore it even doesn't recursively check the Validation. See this SO question for more...

Peter Schneider
  • 2,763
  • 1
  • 13
  • 16