我正在开发一个MVC 5的Web应用程序。在我的Razor视图中,有一个表格,其中包含几行数据。每行数据旁边都有一个删除按钮。当用户单击删除按钮时,我想让Bootstrap Modal弹出并询问用户确认是否要删除。
add line before foreach loop
@Html.Hidden("item-to-delete", "", new {@id = "item-to-delete"}) @foreach (var item in Model) { <td> <button type="" class="btn btn-sm blue deleteLead" data-target="#basic" data-toggle="modal" data-id="@item.bookid">delete</button> </td> }
2.我的模态框
<div class="modal fade" id="basic" tabindex="-1" role="basic" aria-hidden="true" style="display: none;">
<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">book Delete Confirmation</h4>
</div>
<div class="modal-body">
Are you Sure!!! You want to delete this Ad?
</div>
<div class="modal-footer">
<button type="button" class="btn blue" id="btnContinueDelete">Continue</button>
<button type="button" class="btn default" data-dismiss="modal">Cancel</button>
</div>
</div>
</div>
</div>
脚本
<script>
$(".deletebook").click(function(e) {
e.preventDefault();
var id = $(this).data('id');
$('#item-to-delete').val(id);
});
$('#btnContinueDelete').click(function() {
var id = $('#item-to-delete').val();
$.post(@Url.Action("Deletebook", "book"), { id: id }, function(data) {
alert("data deleted");
});
});
</script>
在控制台中,我收到了 => Empty string passed to getElementById() 的消息。