Closed
Description
Hi Shibayan,
When using TryValidateModel
method DataAnnotations attributes (for example [Required]) on nested objects/properties are not validated.
public class SampleModel
{
[Required]
public string Name { get; set; }
public string[] Array { get; set; }
public NestedModel Nested { get; set; }
}
public class NestedModel
{
[Required]
public string Name { get; set; }
}
When posting the SampleModel and omitting the Name property, TryValidateModel returns true
and not false
as expected.
Tried with:
{
"name": "test",
"nested":{
}
}
and also with:
{
"name": "test"
}
Is this something you are aware of or a bug?
Ps I found a fix for the behavior described above, and if you are interested I can provide a PR.