我尝试使用引导模式删除行但我错过了.on
函数中的关键细节。以下是所有相关代码:
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);
});
以下是当前返回的内容,
模特:
您即将删除ID为 2 的记录,此程序不可逆转。
在控制台中:
未定义
我似乎无法解决这最后一块。我缺少什么或需要添加什么?这是正确的使用方式和模态吗?我也调查了this问题,但无法解决问题。