Reputation: 15159
I have MVC 5 project that uses unobtrusive validation:
<appSettings>
<add key="ClientValidationEnabled" value="true" />
<add key="UnobtrusiveJavaScriptEnabled" value="true" />
</appSettings>
And here is my model class:
public class LoginModel {
[DataType(DataType.EmailAddress, ErrorMessage = "Problem address")]
[Required]
public string Mail { get; set; }
[DataType(DataType.Password)]
[Required]
public string Password { get; set; }
}
When I enter invalid value in Mail field I always get standard "Please enter a valid email address." which is hard-coded in jquery.validate.js
. My ErrorMessage
value is ignored. Why? Moreover, if I remove ErrorMessage
parameter the standard message is not localized unlike the rest of validation attributes (Required, StringLength). What am I missing?
Upvotes: 2
Views: 223
Reputation: 5503
The purpose of the DataType attribute is not validation, it is used for formatting data in views, choosing which type of input field to generate etc.
The error message comes from the validation attribute. Try:
[EmailAddress(ErrorMessage = "Problem address")]
public string Email{ get; set; }
Upvotes: 1