I have following model:
public class FormularModel
{
[Required]
public string Position { get; set; }
[Required]
[DataType(DataType.EmailAddress)]
public string Email { get; set; }
[Required]
public string Webcode { get; set; }
}
Required validation works fine. But when i try with DataType it doesn’t react.
Here is my razor code for the email control:
@Html.TextBoxFor
(model => model.Email,
new { @style = "width: 175px;", @class = "txtField" }
) *
So, anyone know an answer?
TIA
DataTypeattribute is used for formatting purposes, not for validation.I suggest you use ASP.NET MVC 3 Futures for email validation.
Sample code:
If you happen to be using
.NET Framework 4.5, there’s now a built inEmailAddressAttributethat lives inSystem.ComponentModel.DataAnnotations.EmailAddressAttribute.