0

嗨,我是 MVC 和 jQuery 的新手。任何人都可以请指导我以下。当我单击删除链接时,删除操作永远不会命中。

我的观点:

  <table id="lookupValuesDetailsTable" class="table table-bordered table-striped table-hover">
        <thead>
            <tr>
                <th>Value</th>
                <th>Message</th>
                <th>EffectiveDate</th>
            </tr>
        </thead>
        <tbody>
            @foreach (var item in Model.LookupValues)
            {            
                <tr>

                    <td>@Html.DisplayFor(m => item.Value)</td>
                    <td>@Html.DisplayFor(m => item.Message)</td>
                    <td>@Html.DisplayFor(m => item.EffectiveDate)</td>
                    @* <td>@Html.DisplayFor(m => item.EffectiveDateDateForSorting)</td>*@
                    <td>
                        @Html.ActionLink("Delete", "Delete", "LookupValues", new { area = "Admin", id = item.LookupValueKey }, new { @class = "deleteLink" })

                    </td>
                </tr>
            }

        </tbody>
    </table>

<div id="dialog-confirm" title="CONFIRMATION" class="modal-header">
    <div class="modal-body">
        <p>This item will be deleted. Are you sure?</p>
    </div>
</div>


@section Scripts {
<script type="text/javascript">
     $("#dialog-confirm").dialog({
        autoOpen: false,
        modal: true,
        resizable: false,
        height: 180,
    });

    $(".deleteLink").click(function (e) {
        e.preventDefault();
        var targetUrl = $(this).attr("href");

        $("#dialog-confirm").dialog({
            buttons: {
                "Confirm": function () {
                    window.location.href = targetUrl;
                },
                "Cancel": function () {
                    $(this).dialog("close");
                }
            }
        });

        $("#dialog-confirm").dialog("open");
    });

</script>

我的控制器(LookupValuesController):

 [HttpPost]
    public ActionResult Delete(Guid id)
    {
        var lookupValueDetails = adminService.GetLookupValues(id);
        var model = AddLookupValueMappings.ToModel(id, lookupValueDetails);
        return View();
    }

谁能告诉我,我做错了什么。

4

1 回答 1

0

首先删除 e.Prevntdefault(); 然后在下面尝试..虽然我还没有检查过...

$('.delete').click(function () {
            var answer = confirm('Do you want to delete this record?');
            if (answer) {
                $.post(this.href, function () {
                    window.location.reload(); //Callback
                });
                return false;
            }
            return false;
        });

控制器如下:-

@Html.ActionLink("Delete", "Delete", new { area = "Admin", id = item.LookupValueKey }, new { @class = "delete" })
于 2013-09-30T05:35:47.410 回答