c# - 选中复选框时调用 ActionResult

标签 c# jquery asp.net-mvc

我试图在选中复选框时调用 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">&times;</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/

相关文章:

javascript - 注入(inject)的脚本没有响应 page-js

asp.net-mvc - 如何使用 Bootstrap Accordion 和 ASP.NET MVC 展开和折叠表格行?

c# - 如何测试所有 ASP.NET Core Controllers 的依赖注入(inject)是否有效?

c# - 如何按从上到下的设计顺序或设置顺序循环检查复选框

c# - WPF MVVM Datagrid 具有 Combobox 更新 selectedItem 更改上的其他列

javascript - 使用 jQuery 删除具有相同类名的多个表

jquery - 如何本地化 JQueryUI 模式对话框上的按钮

c# - Parse.com 查询的主线程问题

asp.net - 小数和整数的自定义模型绑定(bind)器 : How to get the string value before MVC and do a smarter conversion

asp.net-mvc - 在 Azure 中使用哪个负载均衡器