Email address validation using ASP.NET MVC data type attributes
If you are using .NET Framework 4.5, the solution is to use EmailAddressAttribute
which resides inside System.ComponentModel.DataAnnotations
.
Your code should look similar to this:
[Display(Name = "Email address")]
[Required(ErrorMessage = "The email address is required")]
[EmailAddress(ErrorMessage = "Invalid Email Address")]
public string Email { get; set; }
Try Html.EditorFor
helper method instead of Html.TextBoxFor
.