我正在寻找成功:在删除操作完成时删除已检查行的函数。现在我需要每次刷新以检查行是否被删除
这是我的Jquery
$('#del').click(function () {
var delData = [];
$("input:checked").each(function () {
delData.push($(this).val());
});
$.ajax({
type: "POST",
url: "/Home/Delete",
data: { 'ids': delData },
success: function (data) {
if (data = true) {
jQuery("tr input:checked").remove(this);
}
else {
alert("yooo")
}
},
dataType: "json",
traditional: true
});
return false;
});
我的控制器
public ActionResult Delete()
{
return View();
}
[HttpPost]
public void Delete(List<int> ids)
{
int[] TXId = ids.ToArray();
foreach (int i in TXId)
{
int deleted = new Voucher().Delete(i);
}
}
我的模特(仅删除)
namespace Finance.Models
{
public class Voucher
{
public int Delete(int TXId)
{
using (SqlConnection con = new SqlConnection(CONNECTION_STRING))
{
using (SqlCommand cmd = new SqlCommand("DELETE FROM Ledger WHERE TXId = @TXID", con))
{
con.Open();
cmd.Parameters.AddWithValue("@TXID", TXId);
int modified = cmd.ExecuteNonQuery();
if (con.State == System.Data.ConnectionState.Open) con.Close();
return modified;
}
}
}
#endregion
}
并附上我的观点
<table class="tab sortable" id="sortabletable">
<tr class="heading">
<th>
Date
</th>
<th id="to">
To</th>
<th>
Voucher ID
</th>
<th>
Description
</th>
<th>
Amount
</th>
<th>
Account
</th>
<th> User</th>
<th>Select </th>
</tr>
@foreach (var item in Model.MyList) {
<tr class="rows">
<td>
@item.Date.ToShortDateString()
</td>
<td>
@Html.DisplayFor(modelItm => item.Per)
</td>
<td>
@Html.DisplayFor(modelItem => item.VId)
</td>
<td>
@Html.DisplayFor(modelItem => item.Des)
</td>
<td>
@Html.DisplayFor(modelItem => item.Amt)
</td>
<td>
@Html.DisplayFor(modelItem => item.AId)
</td>
<td>
@Html.DisplayFor(modelItem => item.UId)
</td>
<td><input type="checkbox" name="thecheckbox" value="@item.TXId" class ="cbox" checked/></td>
</tr>
}
</table>
答案 0 :(得分:0)
在成功功能中添加以下行
$("#sortabletable input[type=checkbox]:checked").closest("tr").remove();