2011-11-15 120 views
1

我使用不顯眼的驗證來驗證表單。它適用於大多數瀏覽器 - 兼容模式下的IE7,IE8,FF和Chrome。但是,在IE8獨立模式下,會觸發驗證並顯示消息。當我到現場並重新鍵入該值時,瀏覽器在第一次按下按鍵後掛起。該錯誤消息不會自動消失。這發生在所有表單和所有類型的驗證屬性 - 必需,遠程或正則表達式。asp.net MVC3不顯眼的驗證導致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()); 
} 
+0

你能削減你的代碼下來,證明了錯誤,您可以在這裏粘貼到看樣嗎? –

+0

我已添加源代碼。謝謝。 – Madhu

+0

嘿@Madhu - 你有沒有什麼運氣可以解決這個問題。我有類似的問題,ie8 – Rob

回答

0

儘量使用最新版本的jquery validation 1.9

+0

感謝您的及時迴應。不幸的是,這並沒有解決問題。 – Madhu

+0

在另一個項目中,爲驗證消息生成的html是。但是,在這個項目中,生成的html對於=「Name」generated =「true」>是 Madhu

相關問題