0

Are the DataAnnotations executed in the same order as they are specified or in a random order. Example :

public class Model1
{
     [Required]
     [Range(3,45,ErrorMessage="out of range")]
     [emailaddress]
     public string email_id {get;set;}

}

Does the annotations are checked in the same way as declared or how?

Phaneendra
  • 103
  • 9

1 Answers1

1

it's probably checked in the order of logic and performance, not the order you wrote it. If the field is required, it would be pointless to check Range first. For controls at the same level, it is checking according to performance. it checks the least costly one first so that it does not spend much effort in the case it does not comply with the condition.

Can Çalışkan
  • 274
  • 3
  • 16
  • I wrote a custom data annotation which uses the value of the property and it should not be null. But it is not checking the required attribute and custom data annotation is checked first which is throwing run time error. How to address this problem. – Phaneendra Sep 12 '22 at 15:38
  • If you wrote your custom data annotation, you can check your requirement in your custom data annotation. – Can Çalışkan Sep 12 '22 at 19:30