asp.net MVC3 不引人注目的验证导致 IE8 浏览器挂起
我正在使用不显眼的验证来验证表单。它适用于大多数浏览器 - 兼容模式下的 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试使用最新版本的jquery验证1.9
Try to use the latest version of jquery validation 1.9