2014-03-19 18 views
0

我有一個包含一個錶行,並對其內容的局部視圖...更新與AJAX的結果錶行調用

@{string divid = "lostbusiness_" + Model.lostid;} 
<tr id="@divid"> 
    @using (Ajax.BeginForm(
     "UpdateLostBusiness", 
     new AjaxOptions 
     { 
      HttpMethod = "POST", 
      OnSuccess = "lostbusinessupdated" 
     })) 
     { 
     <td> 
      <script type="text/javascript"> 
       function lostbusinessupdated(result) { 

        $("#@divid").html(result); 
       } 
      </script> 
      @Html.Hidden("lostid", Model.lostid) 
      @Html.Hidden("bookingid", Model.bookingid) 

      @Ajax.ActionLink("Delete", 
        "DeleteLostBusiness", new { lostid = Model.lostid }, 
        new AjaxOptions 
        { 
         Confirm = "Delete?", 
         HttpMethod = "POST", 
         OnSuccess = "postmessage('lostbusiness_Deleted_" + Model.lostid + "')" 
        }) 
     </td> 
     <td> 
      @Html.DropDownListFor(model => model.lost_code, (SelectList)ViewBag.ddllostcodes, "--Select Users--") 

     </td> 
     <td>@Html.TextBox("lost_reason", Model.lost_reason)<input type="submit" value="update" /></td> 



    } 
</tr> 

上述局部視圖在成功的Ajax返回到主視圖呼叫。 我不知道在哪裏插入結果。由於部分視圖包含表格行,所以表格行被複制,因此生成的html包含具有相同標識的嵌套表格行。

我會將表格行打開和關閉標記移動到局部視圖之外,但這會導致插入ajax函數出現問題。

回答

1

什麼JQuery的方法replaceWith()(JQuery replaceWith docs)

「中的組與所提供的新的內容匹配的元素的替換每個元素並返回所述一組被移除元件。」 所以:

$("#@divid").replaceWith(result); 
+0

是的 - 這就是我需要的!謝謝。 – tintyethan