asp.net MVC3 不引人注目的验证导致 IE8 浏览器挂起

发布于 2024-12-15 11:48:03 字数 4439 浏览 4 评论 0原文

我正在使用不显眼的验证来验证表单。它适用于大多数浏览器 - 兼容模式下的 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());
}

I am using unobtrusive validation to validate a form. It works in most of the browsers - IE7, IE8 in compatibility mode, FF and Chrome. However, in IE8 stand-alone mode, it fires the validation and message is shown. When I go to the field and retype the value there, the browser hangs after the first key press. The error message is not automatically disappearing. This happens for all forms and for all types of validation attributes - Required, Remote or Regular expression.

I am using jquery 1.6.4 and jquery validation 1.8.1.

Could anybody please help me ?

View Model

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
    }
}

Action

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

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

View

    @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 Hint - 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());
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

ㄟ。诗瑗 2024-12-22 11:48:03

尝试使用最新版本的jquery验证1.9

Try to use the latest version of jquery validation 1.9

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文