我试图在选中复选框时调用 ActionResult,但我不知道为什么它不起作用 下面是我的代码。
--复选框
<td>
<input type="checkbox" id=@item.EmployeeId />
</td>
--模态
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title" id="myModalLabel">Modal title</h4>
</div>
<div class="modal-body" id="ModalBody">
</div>
</div>
</div>
</div>
$('input[type="checkbox"]').on('change', function (e)
{
if (e.target.checked)
{
var id = $(this).attr('id');
var url = "Employee/ShowPopUpDelete?id=" + id;
$("#ModalBody").load(url,function()
{
$("#myModal").modal("show");
})
}
});
</script>
-- Controller
public ActionResult ShowPopUpDelete(int id)
{
Employee temp = new Employee();
temp = EM.FindById(id);
ViewBag.Msg = "Are you sure?";
return PartialView("Delete",temp);
}
FindById 返回具有给定 ID 的 Employee 对象。当我调试时,它只是忽略我的 ShowPopUpDelete ActionResult 。我很高兴知道我做错了什么。
最佳答案
试试这个:
复选框
<td>
<input type="checkbox" id="1234" />
</td>
脚本
$("#1234").change(function()
{
if (this.checked)
{
var id = parseInt($(this).attr('id'));
var url = "@Url.Action("ActionName", "ControllerName")" + "?id=" + id;
$("#modelbody").load(url,function()
{
$("#myModal").modal("show");
})
}
});
关于c# - 选中复选框时调用 ActionResult,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60108928/