DataAnnotation error message
Posted
by user281180
on Stack Overflow
See other posts from Stack Overflow
or by user281180
Published on 2010-05-11T08:01:15Z
Indexed on
2010/05/11
8:04 UTC
Read the original article
Hit count: 425
asp.net-mvc-2
I have the following code;
[RegularExpression(@"^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$", ErrorMessage = "Invalid Email Address")]
public string Email { get; set; }
In my view I have:
<tr><td>Email</td><td><%=Html.TextBox("Email", Html.Encode(Model.Email), new { Class = "edit_control" })%></td><td><%= Html.ValidationMessageFor(model => model.Email)%></td></tr>
My problem is when I insert an invalid email, it still saves. If I let other required fields empty then the message is displayed. Else, if this is the only field with an error, the message doesn`t get displayed.
I want it to display the message and not save the form values.
© Stack Overflow or respective owner