简体   繁体   中英

Bootbox ASP.NET MVC Confirmations

Hi I'm trying to get Confirm dialog (Bootbox) to work. It displays the confirmation dialog but doesn't do anything upon pressing the Ok button.

 $(document).on("click", "#close", function (e) {
            e.preventDefault();
            var $this = $(this);
            bootbox.confirm("Are you sure you want to close this Service Request? This operation cannot be reversed."
                , function (result) {
                    if (result) {
                        $this.closest('form').submit();
                    } else {
                        console.log("user declined");
                    }
                });
        });

I believe this is wrong:

$this.closest('form').submit();

My button is <td><a href="@Url.Action("CloseLog", "Log", new {id = item.LogID})"><span class="glyphicon glyphicon-trash" id="close"></span></a>

Question is how do I get the ok button to work?

EDIT: Can I call this function from onClick in button? If so How?

$(document).on("click", ".alert", function (e) {
            var link = $(this).attr("href"); // "get" the intended link in a var
            e.preventDefault();
            bootbox.confirm("Are you sure?", function (result) {
                if (result) {
                    document.location.href = link;  // if result, "set" the document location      
                }
            });
        });

Based on your comment

$(document).ready(function()
{
  $("#close").click(function()
  {
     var link = $(this).attr("href"); // "get" the intended link in a var
     var result = confirm("Are you sure?");
     if(result)
     {
       document.location.href = link;  // if result, "set" the document location      
     }
  });
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM