I'm attempting to delete a row using a bootstrap modal but I'm missing a key detail in my .on
function. Here is all of the relevant code:
Controller.cs:
@foreach (var item in Model)
{
<a class="btn btn-danger btn-sm" data-employee-id="@item.EmployeeID" value="@item.EmployeeID"</a>
}
<div id="modalDelete" class="modal fade" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title" style="text-align-last: center">Confirm Delete</h4>
</div>
<div class="modal-body">
<h5 style="text-align-last: center">You are about to delete the record with an ID of <b class="title"></b>, this procedure is irreversible.</h5>
<h5 style="text-align-last: center">Are you sure you want to delete?</h5>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-danger btn-delete">Delete</button>
<button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
</div>
</div>
</div>
Script.js:
$('#modalDelete').on('show.bs.modal', function (e) {
var data = $(e.relatedTarget).data();
$('.title', this).text(data.employeeId);
});
$('#modalDelete').on('click', '.btn-delete', function (e) {
var id = $(this).data('employee-id');
console.log(id);
});
Here is what is currently returned,
The model:
You are about to delete the record with an ID of 2, this procedure is irreversible.
In the console:
undefined
I cannot seem to solve this last piece. What am I missing or what do I need to add? Is this the correct way to use and modal? I have also looked into this question but was not able to resolve it.