In many scenario, it necessary to pop up the confirm alert box while deleting ,saving and editing information in Asp .Net MVC application. So let us discuss about how can we achieve using JQuery code .
Controller
Create simple controller and generating view based on the controller as shown below.
View (index)
As shown below code, we had created ConfirmationDialog function using javascript to show the popup with alert message. Next creating a AcionLink control which will show the popup by calling the javascript method in the onclick event.
1 2 3 4 5 6 7 8 9 10 |
<script type="text/javascript"> function ConfirmationDialog() { if(confirm("Are you sure to continue?")) return true; else return false; } </script> @Html.ActionLink("Click to Confirm", "Confirmation", null, new { onclick = "return ConfirmationDialog()" }) |
OUTPUT:
If you click ok, it will redirect to the Confirmation view