You can use confirm
of Javascript which will return a bool
value after a message shows on the browser or use css bootstrap since you have it on your application.
Confirm Javascript
Just add a confirm on the onclick
event on the a
tag. For sample:
<a href="@(Url.Action<UnitsController>(c => c.Delete(Model.Entity.Id)))"
class="btn btn-primary col-md-offset-9 col-md-3"
onclick="return confirm('Are you sure you want to delete this item?')">Delete</a>
CSS Bootstrap
Since you are using css bootstrap, you could try it without poblems. For sample.
Define the css tag for the modal window
<div id="deleteConfirm" class="modal">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title">Delete Entity</h4>
</div>
<div class="modal-body">
<p>Are you sure you want to delete this item?</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
<button id="deleteButton" type="button" class="btn btn-primary">Confirm</button>
</div>
</div>
</div>
</div>
Define the event click for the deleteButton
to make a ajax request and delete it.
$("#deleteButton").on("click", function(e) {
$.ajax({
url: "@Url.Action("Delete", "Controller")",
method: "POST",
data: { id: @Model.Id }
})
.done(function(data) {
// hide the modal
$("#deleteConfirm").modal("hide");
if (data.success) {
// ok
} else {
// show errors
}
});
});
And finally, show the modal on a button that should confirm the delete. For sample:
<a href="@(Url.Action<UnitsController>(c => c.Delete(Model.Entity.Id)))"
class="btn btn-primary col-md-offset-9 col-md-3"
id="deleteConfirmButton">Delete</a>
and set the event.
$("#deleteConfirmButton").on("click", function() {
$("#deleteConfirm").modal("show");
});