1

我正在尝试使用 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 = "updateclassID" 它是 TR 的类名。我想按类而不是元素 id 替换数据。

4

1 回答 1

2

请改用该OnComplete属性:

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

在 JavaScript 中:

function updateRows(data) {
    $('.updateclassID').html(data);
}
于 2014-10-18T16:06:40.543 回答