2012-03-04 39 views
0

我有將點擊ajax.actionlink後返還,下面的部分觀點: -客戶端數據標註不工作對containe ajax.beginform我的asp.net mvc的內部的局部視圖

@model System.Models.Answer 
@{ 
    ViewBag.Title = "Create"; 
} 
<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> 
<div id = "partialWrapper"> 
@using (Ajax.BeginForm("Create", "Answer", new AjaxOptions 
{ 
    HttpMethod = "Post", 
    InsertionMode = InsertionMode.InsertAfter, 
    UpdateTargetId = "incrementanswer", 
    OnSuccess = "removePartial" 
})) 

{ 
    <div id = "returnedquestion"> 
    @Html.ValidationSummary(true) 

    <fieldset> 
     <legend>Answer here</legend> 
     <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.IsRight) 
     </div> 
     <div class="editor-field"> 
      @Html.DropDownList("IsRight", String.Empty) 
      @Html.ValidationMessageFor(model => model.IsRight) 
     </div> 
    </fieldset> 
    <input type= "hidden" name = "questionid" value = @ViewBag.questionid> 
    <input type= "hidden" name = "assessmentid" value = @ViewBag.assessmentid> 
    <input type="submit" value="Add answer" /> 
</div> 
} 
</div> 

問題是,如果我點擊提交按鈕,同時離開所需的文件空白,那麼將不會顯示客戶端驗證IsRight和描述字段是必需的,而是整個視圖(包含佈局)將被返回,那麼可能是什麼問題?

這裏是正在從partila視圖稱爲操作方法: -

[HttpPost] 
     public ActionResult Create(int questionid, Answer a) 
     { 
      if (ModelState.IsValid) 
      { 
     repository.AddAnswer(a); 
      repository.Save(); 
      return PartialView("_details",a); 
      } 
      return View(a); 

和ajax.actionlink,將返回的局部視圖: -

<div id ="link"> 
@Ajax.ActionLink("Add New Answer", "Create", "Answer", 
     new { questionid = Model.QuestionID }, 
      new AjaxOptions 
      { 

       HttpMethod = "Get", 
       UpdateTargetId = "link", 
       InsertionMode = InsertionMode.InsertAfter, 
       LoadingElementId = "progress" 


         }) 
         </div> 

回答

0

你啓用不顯眼的驗證?

<appSettings> 
    <add key="ClientValidationEnabled" value="true"/> 
    <add key="UnobtrusiveJavaScriptEnabled" value="true"/> 
</appSettings> 

您是否正確鏈接了這些腳本文件?

<script src="http://ajax.microsoft.com/ajax/jQuery/jquery-1.4.2.min.js"></script> 
    <script src="http://ajax.microsoft.com/ajax/jquery.validate/1.7/jquery.validate.min.js"></script> 
    <script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"><script> 
+0

是的,我可以看到所有這些腳本在腳本文檔部分下被成功解僱後,我運行應用程序,我也將Jquery.validate腳本移動到部分視圖,而不是在主視圖和問題沒有解決。 – 2012-03-05 22:23:17

1

您需要重新綁定非侵入式JavaScript在Ajax請求的成功一部分。如下:

$.validator.unobtrusive.parse($(「div#divWizard」)); 

請查看以下link to my blog以作進一步參考。

相關問題