2013-06-12 121 views
1

在我進入細節,這是我驗證總結工作,但個別驗證消息不工作

環境:VS 2008的ASP.NET MVC 2

基本型號代碼

[DisplayName("Current Application Status")] 
    [Required(ErrorMessage = "Current Status has to be provided")] 
    public virtual int CurrStatus{ get; set; } 

腳本引用

<link href="../../Content/Site.css" rel="stylesheet" type="text/css" /> 
    <link href="../../Content/jqueryui.css" rel="stylesheet" type="text/css" /> 
    <script src="../../Scripts/jquery-1.9.1.js" type="text/javascript"></script> 
    <script src="../../Scripts/jquery-ui-1.10.3.custom.js" type="text/javascript"></script> 
    <script src="../../Scripts/jquery.validate.js" type="text/javascript"></script> 
    <script src="../../Scripts/jquery.validate.unobtrusive.js" type="text/javascript"></script> 

查看代碼

 <tr> 
     <td><%= Html.LabelFor(model => model.CurrStatus) %></td> 
     <td> 
      <%= Html.DropDownListFor(model => model.CurrStatus, Model.CurrentStatus, "-- Select Current Status --").ToString().Replace("CurrStatus", "Application.CurrStatus")%> 
      <%=Html.ValidationMessageFor(model=>model.CurrStatus) %> 
     </td> 
    </tr> 

控制器代碼

 [AcceptVerbs(HttpVerbs.Post)] 
    public ActionResult Create([Bind(Prefix = "Application")] Application model) 
    { 
     try 
     { 
      if (ModelState.IsValid) 
      { 
        //save to db 
      } 
      else 
      { 
       InitSelectListItems(); 
       model.CurrentStatus = CurrentStatusModel.GetModelInstance().GetAllAsSelectListItems(); 
       return View(model); 
      } 
      return RedirectToAction("Index"); 
     } 
     catch 
     { 
      return View(); 
     } 
    } 

在視圖中,驗證摘要顯示與所提交的模型錯誤列表。但是由於某些原因,單個錯誤消息未顯示。最重要的是,在將條目添加到web.config中並將jQUery腳本添加到腳本文件夾後,我啓用了客戶端驗證。客戶端驗證也沒有被觸發。任何幫助,將不勝感激。

回答

2

不知道你驗證摘要助手的樣子,但我可以quess您傳遞「真」值給助手這樣

@ Html.ValidationSummary(真)

這將排除彙總所有性的判定誤差修改根據MSDN:

真正只需要有總括顯示模型級的錯誤,還是假 有總結顯示所有錯誤。

能否請您詳細闡述更多關於您添加什麼JQuery的文件,以及哪些變更你的web.config中提出?

難道你沒有忘記通過捆綁包或腳本標籤將JQuery文件包含到應用程序中嗎?

+0

我試着將ValidationSummary添加到true。它隱藏了顯示的錯誤摘要,但它也沒有顯示模型級錯誤。我不確定我瞭解驗證摘要助手。我沒有用於驗證摘要的自定義擴展。我已經包含了所有的JQuery腳本標籤。我在原始文章中使用了jQuery部分。 – vikramjb

+0

這是我得到的最接近的答案,所以我接受它。感謝您的時間。 – vikramjb