开发者

MV3 input validation - IE8 & IE9 behave differently

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"


In my case, which is a lot like yours, I found that updating jquery.validate.js was the way to go. There is a reported bug on version 1.8.0 of jquery validation about IE 7, 8 and 9.

After getting the latest version everything started to work.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜