【发布时间】:2015-08-09 00:14:18
【问题描述】:
我使用这种方法从表中删除一行。我能够从数据库中删除该行并显示“状态”警报。但是我必须刷新页面才能从页面中删除该行。我该怎么办?
<script type="text/javascript">
function DeleteRow(btnDel) {
$.get('../ProtocolSummary/DeleteRowATList?id2=' + btnDel, function(data, status){
alert("Status: " + status);
});
$(btnDel).closest("tr").remove();
}
</script>
***Html***
<tbody>
<% var ATRowId = 0; foreach (var item in Model.List)
{%>
<tr style="text-align:center">
<td><%=Html.TextAreaFor(m => m.List[RowId].Type, new { value = @Model.List[ATRowId].Type, @style = "width:260px;" })%>
<%=Html.HiddenFor(x=>x.List[RowId].AssistiveId,Model.ATList[RowId].AssistiveId) %></td>
<td><%=Html.TextAreaFor(m => m.List[RowId].Schedule, new { value = @Model.List[ATRowId].Schedule, @style = "width:260px;" })%></td>
<td><%=Html.TextAreaFor(m => m.List[RowId].Storage, new { value = @Model.List[ATRowId].Storage, @style = "width:260px;" })%></td>
<td style="width:50px"><input type="button" value="delete" class="btnDel" style="float:right;width:20px" onclick="DeleteRow(<%= item.AssistiveId%>)" /></td>
</tr>
<% ATRowId++;
}%>
</tbody>
【问题讨论】:
-
你能给你提供 HTML 吗?
-
@Manashvi Birla,为什么需要使用 ajax 从 DOM 中删除元素?
-
以免页面刷新
-
首先,删除操作是 POST,而不是 GET!根据您生成的查询字符串,
btnDel在字符串或数字中,而不是 html 元素,因此$(btnDel)将不起作用。显示表格中一行的 html
标签: javascript asp.net-mvc delete-row