I have a property in my PersonDTO class:
[EmailAddress] public string Email { get; set; }
It works fine, except that I want to allow empty strings as values for my model if I send JSON from the client side:
{ Email: "" }
I received 400 bad request responses to 400 bad request and
{"$id":"1","Message":"The Email field is not a valid e-mail address."}
However, this allows you to omit the email value:
{ FirstName: "First", LastName: 'Last' }
I also tried:
[DataType(DataType.EmailAddress, ErrorMessage = "Email address is not valid")]
But that does not work.
As I understand it, the Data Annotations Extensions package also does not allow an empty string.
So I'm wondering if there is a way to set up a standard EmailAddressAttribute to allow blank lines so that I don't have to write my own validation attribute.
validation asp.net-mvc attributes
makambi
source share