MV3 input validation - IE8 & IE9 behave differently

為{幸葍}努か 提交于 2019-12-21 06:25:47

问题


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"


回答1:


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.



来源:https://stackoverflow.com/questions/6421554/mv3-input-validation-ie8-ie9-behave-differently

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!