I'm currently learning Net core, can anybody share with me how to override dataAnnotation ErrorMessage from string to object.
instead of ErrorMessage as string
[RegularExpression(@"^[a-zA-Z0-9._-]{3,15}$", ErrorMessage = "Please make sure username is between 3 to 15 character and may also contain '._-' special character only.")]
public string Username { get; set; }
to ErrorMessage as object
[RegularExpression(@"^[a-zA-Z0-9._-]{3,15}$", ErrorMessage = new ErrorModel { MESSAGE = "Something went wrong when updating username.Please contact system admin if issue persist.", STATUS_CODE = "1"})]
public string Username { get; set; }
I have created an ErrorModel class
public class ErrorModel
{
public string STATUS_CODE { get; set; }
public string MESSAGE { get; set; }
}
I want to override ErrorMessage from string to object for all attribute derived from ValidationAttribute, is this doable?
Regards, Hazmin