asp.net MVC3不显眼的验证导致IE8浏览器挂起

时间:2011-11-15 12:36:07

标签: asp.net-mvc internet-explorer-8 unobtrusive-validation

我正在使用不显眼的验证来验证表单。它适用于大多数浏览器 - 兼容模式下的IE7,IE8,FF和Chrome。但是,在IE8独立模式下,它会触发验证并显示消息。当我转到该字段并在那里重新键入值时,浏览器会在第一次按键后挂起。错误消息不会自动消失。这适用于所有表单和所有类型的验证属性 - 必需,远程或正则表达式。

我使用的是jquery 1.6.4和jquery验证1.8.1。

有人可以帮帮我吗?

查看模型

namespace xxxxx.ViewModel
{
    /// <summary>
    /// SubjectVM
    /// </summary>
    public class SubjectVM
    {
        #region Public Properties

        #region SubjectID
        /// <summary>
        /// SubjectID
        /// </summary>
        public int SubjectID { get; set; }
        #endregion

        #region Name
        /// <summary>
        /// Name
        /// </summary>
        [Display(Name = "Subject Name")]
        [Required(ErrorMessage = "Please enter Name of the subject")]
        [Remote("IsSubjectNameUnique", "Subject", AdditionalFields = "SubjectID",
            ErrorMessage = "The Name given for Subject is already used for another Subject. Please give a different Name.")]
        [UIHint("SingleLineText")]
        [HtmlProperties(MaxLength = 50, Size = 30)]
        public string Name { get; set; }
        #endregion

        #region Description
        /// <summary>
        /// Description
        /// </summary>
        [Display(Name = "Description")]
        [StringLength(500)]
        [UIHint("MultiLineText")]
        [HtmlProperties(Rows = 4, Cols = 25, MaxLength = 500)]
        public string Description { get; set; }
        #endregion

        #region Code
        /// <summary>
        /// Code
        /// </summary>
        [Display(Name = "Subject Code")]
        [Required(ErrorMessage = "Please enter subject code")]
        [Remote("IsSubjectCodeUnique", "Subject", AdditionalFields = "SubjectID",
            ErrorMessage = "The Subject Code given is already used for another Subject. Please give a different Subject Code.")]
        [HtmlProperties(MaxLength = 10, Size = 30)]
        [UIHint("SingleLineText")]
        public string Code { get; set; }
        #endregion
    }
}

动作

#region Create
/// <summary>
/// Create
/// </summary>
/// <returns></returns>
public override ActionResult Create()
{
    SubjectVM blankObject = new SubjectVM();

    return View("Subject", blankObject);
}
#endregion

查看

    @model xxxx.SubjectVM

@{
    ViewBag.Title = "Subject";
}

<h2>Subject</h2>

<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>

@using (Html.BeginForm()) {
    @Html.ValidationSummary(true)
    <fieldset>
        <legend>Subject</legend>

        <div class="editor-label">
            @Html.LabelFor(model => model.Name)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.Name)
            @Html.ValidationMessageFor(model => model.Name)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.Description)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.Description)
            @Html.ValidationMessageFor(model => model.Description)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.Code)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.Code)
            @Html.ValidationMessageFor(model => model.Code)
        </div>

        <p>
            <input type="submit" value="Create" />
        </p>
    </fieldset>
}

<div>
    @Html.ActionLink("Back to List", "Index")
</div>

UI提示 - SingleLineText

@model string
@using xxxx.MVCLibrary;

@{
    HtmlPropertiesAttribute htmlAttributes = null;

    if (ViewData.ModelMetadata.AdditionalValues.ContainsKey("HtmlAttributes"))
    {
        htmlAttributes = (HtmlPropertiesAttribute)ViewData.ModelMetadata.AdditionalValues["HtmlAttributes"];
    }

    @Html.TextBoxFor(Model => Model, htmlAttributes.HtmlAttributes());
}

1 个答案:

答案 0 :(得分:0)

尝试使用最新版本的jquery validation 1.9