How to show confirmation window in jquery in mvc3 using database

I used the submit button to perform the delete operation in mvc3. I want to show a confirmation window when I click the button, so I used below jquery. The query was used for static data, but I want to work with my database. When I click the submit button, a message appears, but even if I click "OK", an error message appears. What to do to make it work.

<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"); } }); } } ); }); 
+4
source share
1 answer

Try the following:

 <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 a β€œconfirmation” dialog in a jQuery UI dialog?

+1
source

All Articles