更改生成链接的代码,以删除重复的id属性(改为使用类名)并添加
data-
用于存储值的属性
TestUserId
<td>
<a href="#" class="confirm-delete" data-id="@testUser.TestUserId">
<i class="fa fa-trash fa-lg text-primary"></i>
</a>
</td>
在脚本中,您可以检索该值并将其分配给
数据-
调用前对话框的属性
open
$('.confirm-delete').click(function () { // modify selector
var id = $(this).data('id');
$('#dialog-modal').data('id', id).dialog("open");
});
并在单击“确定”按钮时检索它
$('#dialog-modal').dialog(
....
buttons: {
'Cancel': function() {
$(this).dialog('close');
},
'OK': function() {
$.post('@Url.Action("DeleteTestUser", "Home")', { id: $('#dialog-modal').data('id') });
$(this).dialog('close');
}
}
});