c# - 如何使用数据库在mvc3中的jquery中显示确认框

标签 c# javascript jquery asp.net

我在 mvc3 中使用提交按钮执行删除操作。 我想显示一个确认框 当我单击按钮时,我使用了下面的 jquery。该查询用于静态数据,但 我想使用我的数据库。当我点击提交按钮时,消息出现但是 即使我单击确定,它也会显示错误消息。我应该怎么做才能让它发挥作用。

<script type="text/javascript">
    $(document).ready(function () {
               $("#button").click(function (event) {
            event.preventDefault();
            var link = this;
            if (confirm("Are you sure that you want to delete this user?")) {
                $.ajax({

                    type: "POST",
                    url: link.href,


                    success: function (data) 
                    {
                        $(link).parents("tr").remove();
                        alert("deleted");                     
                     },

                    error: function (data)
                     {
                        event.preventDefault();
                        alert(" Unsuccessful");
                      }
                });

            }
        }
            );
    });

最佳答案

试试这个:

<asp:Button ID="btn" runat="server" Text="Click"
            OnClientClick="return confirmDialog(this);"
            onclick="btn_Click" />

var confirmed = false;
function confirmDialog(obj)
{
    if(!confirmed)
    {
        $( "#dialog-confirm" ).dialog({
            resizable: false,
            height:140,
            modal: true,
            buttons: {
                "Yes": function()
                {
                    $( this ).dialog( "close" );
                    confirmed = true; obj.click();
                },
                "No": function()
                {
                    $( this ).dialog( "close" );
                }
            }
        });
    }

    return confirmed;
}

http://markmintoff.com/2011/03/asp-net-jquery-confirm-dialog/

How to implement "confirmation" dialog in Jquery UI dialog?

关于c# - 如何使用数据库在mvc3中的jquery中显示确认框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11342428/

相关文章:

javascript - Jasmine toEqual 失败但打印两个对象是相同的

javascript - 单击下拉列表 MVC 4 时显示/隐藏

javascript - 从 API 获取数据并使用 jQuery 将其分离到变量中

c# -/planner/plans 上的 C# : 401 - Unauthorized: Access is denied due to invalid credentials. 图形 API

c# - 收到的 WCF 服务器证书的部分链验证失败

Javascript正则表达式匹配html中的json

jQuery .animate() 强制样式 "overflow:hidden"

c# - 将 Excel 中的数据表列填充为字符串

c# - 将此 .NET 字符串更改为 const 是否会提高性能? IL 会自动执行此操作吗?

javascript - 如何从所有其他标签中删除标签属性?