I'm using DataAnnotations to validate my input fields on a MVC3 application. I'm using regular expressions validations. I get the validation messages on the UI for IE8 & IE9. But I notice the difference when I hit the Save button even after the client side validation has failed. IE9 keeps me on the client side. On IE8 however, the control goes to the controller action, and I have to have a controller side TryValidateModel so that the validation errors out.
Does anyone know why IE8 is doing a server round trip?
Edit: Adding the code. This goes into the cshtml.
@using (Html.BeginForm("Person", "Account", FormMethod.Post))
{
<span class="resultError" id="resultError">
@Html.ValidationMessageFor(model => model.Name, "Name should not contain special characters")
</span>
<table>
<tr>
<td class="editor-label">Name:
</td>
<td class="editor-field">@Html.EditorFor(model => model.Name)
</td>
</tr>
</table>
<input type="submit" name="btnKey" value="Save" />
}
This is the partial class using DataAnnotation. The Person class is driven by EF. So I have to create a metadata class to do the validation.
[MetadataType(typeof(personMetadata))]
public partial class person: EntityObject
{
public class personMetadata
{
[Required]
[RegularExpression(@"[A-Za-z0-9]+")]
public object Name { get; set; }
}
}
Edit: Adding the javascript files that are referenced. "~/Scripts/jquery.validate.min.js" "~/Scripts/jquery.validate.unobtrusive.min.js"