繁体   English   中英

我如何从jQuery中获取一些数据并调用Html.ActionLink

[英]How can I get some data from jQuery and call Html.ActionLink with it

我隐藏了Html.ActionLink,其中“删除”-动作名称,“学生”-控制器名称:

@Html.ActionLink("Delete student", "Delete", "Students", new { id = "" }, new { @id = "DeleteButton", @style = "visibility:hidden;" })

和jQuery代码:

<script type="text/javascript">
    $(document).ready(function () {
        var table = $('#students_table').DataTable();

        $('#btnDelete').click(function () {
            var studentId = table.row('.selected')[0]; //this give me correct id
            //alert(studentId); 
            if (studentId) {
                var href = "?id=" + studentId;
                //$("#DeleteButton").attr(href).click();
                //$('#DeleteButton').attr("?id=" + encodeURIComponent(studentId)).click();
            }
            table.row('.selected').remove().draw(false);
        });

    });
</script>

我用获得的ID调用ActionLink时遇到的问题( $("#DeleteButton").attr(href).click();

PS #btnDelete-这是HTML中简单按钮的ID

用ajax删除:

<script type="text/javascript">
    $(document).ready(function () {
        var table = $('#students_table').DataTable();

        $('#DeleteButton').click(function (event) {
            event.preventDefault();

            var studentId = table.row('.selected')[0]; //this give me correct id
            //alert(studentId); 
            if (studentId) {
                $.get( "URL_TO_BACKEND?id=" + studentId, function() {
                    table.row('.selected').remove().draw(false);
                });
            }
        });
    });
</script>

http://api.jquery.com/jQuery.get/

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM