DataTables警告:table id = tableid - Ajax错误。在asp.net-MVC项目中

时间:2017-12-01 17:01:15

标签: jquery ajax asp.net-mvc datatables

在asp.net-MVC项目中,我从api获取jason数据,并使用jQuery数据表在视图中显示它。它在我的localhost中工作得很好,但在发布之后浏览器给我一个错误。错误按摩是......

DataTables警告:table id = tableid - Ajax错误。有关此错误的详细信息,请参阅http://datatables.net/tn/7

我也检查它显示的浏览器控制台..

HTTP500:SERVER ERROR - 服务器遇到意外情况,导致服务器无法完成请求。 (XHR)GET - http://masum626-001-site1.htempurl.com/api/boardofdirectors?_=1512147088008

我的api

public IHttpActionResult GetBoardOfDirector()
    {
        var boardOfDirector =
            _context.BoardOfDirectors.ToList().Select(Mapper.Map<BoardOfDirector, BoardOfDirectorDto>);
        return Ok(boardOfDirector);
    }

并查看

<table id="tableid" class="table table-bordered table-hover">
<thead>
<tr>
    <th>Name</th>
    <th>Designation</th>
    <th>Educational Qualification</th>
    <th>Catagory</th>
    <th>Comment</th>
    <th>Delete</th>
</tr>
</thead>
<tbody>

</tbody>

$(document).ready(function () {
        var table = $("#tableid").DataTable({
            ajax: {
                url: "/api/boardofdirectors",
                dataSrc: ""
            },
            columns: [
                {
                    data: "name",
                    render: function (data, type, row) {
                        return "<a href='/boardofdirector/edit/" + row.id + "'>" + row.name + "</a>";
                    }
                },
                {
                    data: "designation"
                },
                {
                    data: "educationalQualification"
                },
                {
                    data: "catagory"
                },
                {
                    data: "comment"
                },
                {
                    data: "id",
                    render:function(data) {
                    return "<button class='btn-link js-delete' data-director-id=" + data + ">Delete</button>";
                    }   
                }
                ]
        });

        $("#tableid").on("click", ".js-delete", function () {
            var button = $(this);

            bootbox.confirm("Are you sure you want to delete this record?", function (result) {
                if (result) {
                    $.ajax({
                        url: "/api/boardofdirectors/" + button.attr("data-director-id"),
                        method: "DELETE",
                        success: function () {
                            table.row(button.parents("tr")).remove().draw();
                        }
                    });
                }
            });
        });
    });

0 个答案:

没有答案