2012-04-03 62 views
0

在MVC-i顯示了使用jQuery對話框局部視圖:MVC檢查驗證客戶端負載時的局部視圖

@Html.Raw(@Ajax.ActionLink("replaceText", "AddToMembers", new AjaxOptions { HttpMethod = "GET", UpdateTargetId = "result", InsertionMode = InsertionMode.Replace, OnSuccess = "openPopup" }).ToString().Replace("replaceText" , "<img src='images/btn_12.jpg' width='205' height='72' border='0'>")) 

(AddToMemer返回局部視圖)

我的會員模型類是像此:

 public class Members 
     { 
      public int id { get; set; } 
      [Required(ErrorMessage=" *",AllowEmptyStrings=false)] 

      public string name { get; set; } 
      [Required(ErrorMessage = "*", AllowEmptyStrings = false)] 
      [RegularExpression(@"^\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$", ErrorMessage = "*")] 

      public string email { get; set; } 


      public bool isValid { get; set; } 

      public DateTime date { get; set; } 

     } 

,這是我的局部視圖:(csFile)

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

@using (Html.BeginForm()) { 
    @Html.ValidationSummary(false) 
    <fieldset> 
     <legend >register</legend> 
     <div style="font-family: Tahoma; font-size: 12px;"> 
     <div class="editor-label"> 
      @Html.LabelFor(model => model.name) 
       <br /> 
     </div> 
     <div class="editor-field"> 
      @Html.EditorFor(model => model.name) 
      <br /> 
      @Html.ValidationMessageFor(model => model.name) 
     </div> 

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

     <p align=center> 
      <input id="SubmitButton" type="submit" class="normalText" value="send" /> 
     </p> 
     </div> 
    </fieldset> 


} 

但當對話框加載,我點擊發送按鈕,驗證沒有在客戶端檢查,我重定向到新的頁面,驗證在那裏檢查。 有什麼問題?

+0

可能重複Ajax調用後不工作](http://stackoverflow.com/questions/7048726/mvc3-unobtrusive-validation-not-working-after-ajax-call) – jgauffin 2012-04-03 12:48:56

回答