2012-03-04 22 views
2

我有以下ajax.actionlink: -如何更新使用Ajax.beginform我的asp.net MVC Web應用程序內的兩個DOM元素

<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> 

在上面的鏈接將retrun _answer局部視圖以下哪包含Ajax.Actionlink: -

@using (Ajax.BeginForm("Create", "Answer", new AjaxOptions 
{ 
    HttpMethod = "Post", 
    InsertionMode = InsertionMode.InsertAfter, 
    UpdateTargetId = "incrementanswer", 
})) 

{ 
    <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> 

目前點擊提交按鈕,在「UpdateTargetId =‘incrementanswer’後,將與submition的結果進行更新,但問題是,我還需要刪除當前_answer部分視圖

回答

3

(目前的含點擊提交ajax.beginform後,我已插入仍將顯示的值視圖)加載一個包裝DIV中的局部視圖

<div id="partialWrapper"> 
@Html.partial("yourpartial") 
</div> 

聲明一個OnSuccess事件處理程序

@using (Ajax.BeginForm("Create", "Answer", new AjaxOptions 
{ 
    HttpMethod = "Post", 
    InsertionMode = InsertionMode.InsertAfter, 
    UpdateTargetId = "incrementanswer", 
    OnSuccess="removePartial" 
})) 

定義removePartial

<script> 
function removePartial(){ 
    $("#partialWrapper").remove(); 
    } 
</script> 
相關問題