BootBox javascript确认删除

时间:2015-01-19 08:02:19

标签: javascript confirm bootbox

我正在使用asp.net MVC 5.

Bootbox js

 $(document).on("click", ".MyLink", function (e) {
     bootbox.confirm("Are you sure?", function(result) {
     Example.show("Confirm result: "+result);
     }); 
});

@Html.ActionLink("Delete", "Delete", new { id = item.CustomerID }, new { @class = "MyLink" })

如何删除HTML action link? 请查看代码的完整详细信息: -

Javascript代码: -

<script src="~/Scripts/bootbox.min.js"></script>

    $(document).on("click", ".MyLink", function (e) {
        var self = this;
        bootbox.confirm("Are you sure?", function (result) {
            Example.show("Confirm result: " + result);
            $(self).remove();
        });
    });

HTML代码: -

<h2>Index</h2>

  <p>Content here. <a class="MyLink" href=#>Alert!</a></p>
    <p>
        @Html.ActionLink("Create New", "Create")
    </p>

另请参阅内部<table>代码 参考: -

<table class="table">
        <tr>
            <th> First Name </th>
            <th> Last Name </th>
            <th></th>
        </tr>

    @foreach (var item in Model) {
        <tr>
            <td> @Html.DisplayFor(modelItem => item.FirstName) </td>
            <td> @Html.DisplayFor(modelItem => item.LastName) </td>
            <td>
                @Html.ActionLink("Edit", "Edit", new { id=item.CustomerID }) |
                @Html.ActionLink("Details", "Details", new { id = item.CustomerID }) |
                @*@Html.ActionLink("Delete", "Delete", new { id = item.CustomerID, @class = "MyLink" })*@
                <a href="@Url.Action("Delete", new { id = item.CustomerID })" class="MyLink">Delete</a>
            </td>
        </tr>
    }

另请参阅Controller代码供您参考: -

public ActionResult Delete(int? id)
    {
        if (id == null)
        {
            return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
        }
        Customer customer = db.Customers.Find(id);
        db.Customers.Remove(customer);
        db.SaveChanges();
        if (customer == null)
        {
            return HttpNotFound();
        }
        return RedirectToAction("Index");
        //return View(customer);
    }

0 个答案:

没有答案