【问题标题】:how to add client confirmation on delete record in asp.net core 1.0如何在asp.net core 1.0中的删除记录上添加客户端确认
【发布时间】:2017-03-06 17:57:24
【问题描述】:

我使用的是 asp.net core 1.0,在此我想在删除记录上添加客户端确认

下面是我的代码

@model IEnumerable<Login.Model.UserAccount>
@{
    ViewData["Title"] = "Home Page";
}



<div class="row">
    <div class="col-md-12">
        <h2>Registered user</h2>
        @if (Model.Any())
        {
            <table class="table">
                <tr>
                    <th>First name</th>
                    <th>Last Name</th>
                    <th>EmaiID</th>
                    <th>Use Name</th>
                    <th></th>
                </tr>
                @foreach (var item in Model)
                {
                    <tr>
                        <td>@item.FirstName</td>
                        <td>@item.LastName</td>
                        <td>@item.Email</td>
                        <td>@item.UserName</td>
                        <td>
                            <a asp-action="Edit" asp-route-id="@item.UserID">Edit</a> |
                            <a asp-action="Delete" asp-route-id="@item.UserID">Delete</a>
                        </td>
                    </tr>
                }
            </table>
        }
        else
        {
            <p> There is no registered users.</p>
        }
    </div>
</div>

在上面的代码中删除操作成功执行,但我想在删除之前添加添加客户端确认,如果操作正常而不是删除,如果操作取消而不是不删除。

【问题讨论】:

  • 听起来你需要这里的javascript代码。有人认为:$('#deleteLink').click(function(e)){ if(!confirm('Are you sure you want to delete)){ e.preventDefault(); } }

标签: asp.net-core-mvc asp.net-core-1.0


【解决方案1】:
function ConfirmDelete()
{
  var x = confirm("Are you sure you want to delete?");

    return X;
}


<input type="button" Onclick="ConfirmDelete()">

【讨论】:

  • 感谢您提供此代码 sn-p,它可能会提供一些即时帮助。一个正确的解释would greatly improve 其教育价值通过展示为什么这是一个很好的解决问题的方法,并将使它对未来有类似但不相同的问题的读者更有用。请edit您的答案添加解释,并说明适用的限制和假设。特别是,if (x) return true; else return false; 与简单的return x; 相比有什么优势?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-06-15
  • 1970-01-01
  • 2016-11-02
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多