I have property in my PersonDTO
class:
[EmailAddress]
public string Email { get; set; }
It works fine, except I want to allow empty strings as values for my model, if I send JSON from client side:
{ Email: "" }
I got 400 bad request
response and
{"$id":"1","Message":"The Email field is not a valid e-mail address."}
However, it allows omitting email
value:
{ FirstName: "First", LastName: 'Last' }
I also tried:
[DataType(DataType.EmailAddress, ErrorMessage = "Email address is not valid")]
but it does not work.
As far as I understood, Data Annotations Extensions
pack does not allow empty string either.
Thus, I wonder if there is a way to customize the standard EmailAddressAttribute
to allow empty strings so I do not have to write custom validation attribute.