MVC ajax表单是否支持UpdateTargetId的CCS类名而不是elementId?

时间:2014-10-18 16:01:03

标签: asp.net-mvc asp.net-mvc-ajax

我正在尝试使用MVC ajax表单执行操作。我想通过行动的响应来更新内容。就像我有两个用不同的id命名的TR标签。当我点击第二个TR(TD)中出现的删除按钮然后需要用TR(TD)替换动作的响应时,是否可以使用类名更新内容以及动作响应?

<tr id="EditTR" class="updateclassID">
<td>
@*Some content goes here*@
 </td>
 </tr>
 <tr id="DeletTR" class="updateclassID">
  <td>
   @using (Ajax.BeginForm("DeleteEntranceType", "Admin", new AjaxOptions
    {
       HttpMethod = "POST",
        InsertionMode = InsertionMode.Replace,
        LoadingElementId = "LoadingID",
        UpdateTargetId = "updateclassID"
      }
     ))
     {
      <p class="alert alert-danger">
        Are you sure want to delete this Entrance permanently. Associated student's exams and their plans also deleted?
        <button class="btn btn-success btn-xs">Yes</button>&nbsp;<button class="btn btn-default btn-xs" onclick="togglesingle('delete-@item.EntranceTypeID')">No</button>
      </p>    
 }
 </td>
 </tr>

你可以注意到我把UpdateTargetId =&#34; updateclassID&#34;它是TR的类名。我想按类而不是元素id替换数据。

1 个答案:

答案 0 :(得分:2)

改为使用OnComplete属性:

new AjaxOptions
{
    HttpMethod = "POST",
    InsertionMode = InsertionMode.Replace,
    LoadingElementId = "LoadingID",
    OnComplete = "updateRows"
 }

在JavaScript中:

function updateRows(data) {
    $('.updateclassID').html(data);
}