Unable to retrieve data by making an ajax call from my controller to view in mvc

Unable to retrieve data by making an ajax call from my controller to view in mvc

Srujan_PandaSrujan_Panda Posts: 1Questions: 1Answers: 0

Hi everyone. I got a situation where I'm trying to retrieve the data in json format from my controller to the view by making an ajax call. But I'm getting an error that states the following

DataTables warning: table id={id} - Requested unknown parameter '0' for row 0, column 0. For more information about this error, please see http://datatables.net/tn/4

When I tried to use alert in the view to see what exactly is the data I've received on success of the ajax call, it states undefined.

Here is my code.

In controller:

        [HttpPost]
        public JsonResult GetTechGroups()
        {
            DBConfig dbConfig = new DBConfig();
            var data = dbConfig.tbl_Data.ToList();
            return Json(data);
        }

In view:

@section Scripts{
    <script src="//cdn.datatables.net/1.10.12/js/jquery.dataTables.min.js"></script>

    <script>
        $(document).ready(function () {
            debugger;
            $.ajax({
                method: "post",
                dataType: "json",
                url: '@Url.Action("action", "controller")',
                success: function (data) {
                    alert(data.responseText);
                    $('#tblId').dataTable({
                        data: data,
                        Columns: [
                            { "data": "tblCol" },
                        ]
                    })
                },
                error: function (xhr, ajaxOptions, thrownError) {
                    alert("error buddy!!");
                    alert(xhr.responseText);
                    alert(thrownError);
                }
            })
        })
    </script>
}

I'm not getting an error, but I'm not getting the data as well. As I'm new to this I couldn't understand where exactly the error is. Could someone please help me out of this.

Thanks in advance.

This discussion has been closed.