Home > OS >  Model Validation in .Net Core
Model Validation in .Net Core

Time:09-13

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?

CodePudding user response:

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.

  • Related