srkirkland / DataAnnotationsExtensions

Validation extensions for DataAnnotations, including optional MVC client validation implementations
https://dataannotationsextensions.apphb.com/
BSD 3-Clause "New" or "Revised" License
308 stars 86 forks source link

Email DataAnnotations #53

Closed RaviMal closed 11 years ago

RaviMal commented 11 years ago

Hi, I'm new to this but I think I found a bug with the email Data Annotation.

I have a property in a c# mvc model as follows:

    [DataType( DataType.EmailAddress )]
    [Display( Name = "Site Email:" )]
    [StringLength( 255 )]
    [Email( ErrorMessage = "Invalid Site Email Address" )]
    public string SiteEmail { get; set; } 

I have just implemented my views to either display or not display certain input fields on the web page. When I don't display this email address, and I post my View back, ModelState.IsValid is failing on this control. You can see that the property has no value, but for some reason, the error message returned is "Invalid Site Email Address".

RaviMal commented 11 years ago

I think I have resolved my own issue. I had to add a hidden field to represent the value of the property in the view even though I wasn't displaying the control.