我正在尝试使用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> <button class="btn btn-default btn-xs" onclick="togglesingle('delete-@item.EntranceTypeID')">No</button>
</p>
}
</td>
</tr>
你可以注意到我把UpdateTargetId =&#34; updateclassID&#34;它是TR的类名。我想按类而不是元素id替换数据。
答案 0 :(得分:2)
改为使用OnComplete
属性:
new AjaxOptions
{
HttpMethod = "POST",
InsertionMode = InsertionMode.Replace,
LoadingElementId = "LoadingID",
OnComplete = "updateRows"
}
在JavaScript中:
function updateRows(data) {
$('.updateclassID').html(data);
}