0

我正在寻找一个成功:删除操作完成时删除选中行的函数。现在我每次都需要刷新来检查该行是否被删除

这是我的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>
4

1 回答 1

0

在您的成功函数中添加以下行

$("#sortabletable input[type=checkbox]:checked").closest("tr").remove();
于 2013-06-05T11:33:32.860 回答