Click here to Skip to main content
15,867,488 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
C#
<pre lang="c#"><pre>[HttpPost]
        public ActionResult CheckEmployee(Chart obj)
        {
            

            SqlConnection con = new SqlConnection(@"Data Source=MAHGOUBND4;Initial Catalog=CTC_Mahgoub;Persist Security Info=True;User ID=sa;Password=8008989;");
            SqlCommand cmd = new SqlCommand("SELECT * FROM cs INNER JOIN( select EmployeeName FROM cs GROUP BY EmployeeName  HAVING Count(*) > 1) " +
                " As DuplicateRows ON DuplicateRows.EmployeeName = cs.EmployeeName)",con);
            cmd.Parameters.AddWithValue("@EmployeeName", obj.EmployeeName);
            cmd.Parameters.AddWithValue("@DuplicateRows", obj.DuplicateRows);



            return Json( JsonRequestBehavior.AllowGet);
        }

and yhis is my view code
HTML
<pre> @model Asp.NETMVCCRUD.Models.Chart
@{
    ViewBag.Title = "CTC";
}
<table id="employeeTable" class="table table-striped table-bordered" style="width:100%">
    <thead>
        <tr>
            <th>Employee Name</th>
            <th>Scour</th>
        </tr>
    </thead>
</table>
<link href="//cdn.datatables.net/1.10.15/css/jquery.dataTables.min.css" rel="stylesheet" />
<link href="https://cdn.datatables.net/buttons/1.3.1/css/buttons.dataTables.min.css" rel="stylesheet" />
<link href="https://cdn.datatables.net/1.10.15/css/dataTables.bootstrap.min.css" rel="stylesheet" />
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet" />
@section scripts{
<script src="//cdn.datatables.net/1.10.15/js/jquery.dataTables.min.js"></script>
<script src="https://cdn.datatables.net/1.10.15/js/dataTables.bootstrap.min.js"></script>
<script src="https://cdn.datatables.net/1.10.15/js/dataTables.bootstrap.min.js"></script>

<script type="text/javascript">
    var Popup, dataTable;
    $(document).ready(function () {

        dataTable = $("#employeeTable").DataTable({

            "ajax": {
                "url": "/chart/CheckEmployee",
                "type": "GET",
                "datatype": "json"
            },
            "columns": [

                { "data": "EmployeeName", "name": "EmployeeName", "autoWidth": true },
                { "data": "DuplicateRows", "name": "DuplicateRows", "autoWidth": true },

            ],
            "orderable": false,
            "searchable": false,
            "width": "150px",
            "dom": "Bfrtip",
            
            "language": {

                "emptyTable": "No data found, Please click on Add New Button"
            }
        });
    });

</script>
}


What I have tried:

and i show this Error
DataTables warning: table id=employeeTable - Ajax error. For more information about this error, please see http://datatables.net/tn/7
Posted
Updated 7-Aug-20 0:56am
Comments
Sandeep Mewara 7-Aug-20 6:52am    
DataTables warning: table id=employeeTable - Ajax error
Is that the total error and exact one?
silantmagicbbb 7-Aug-20 7:06am    
can you update my code iam try alot of way but all of thim failed

1 solution

Quote:
C#
[HttpPost]
public ActionResult CheckEmployee(Chart obj)
JavaScript
"ajax": {
    "url": "/chart/CheckEmployee",
    "type": "GET",
    "datatype": "json"
},
Your action requires a POST request, and requires a Chart object as its parameter.

Your Javascript is making a GET request, and is not passing any parameters.

Check the developer console in your browser, and you'll see that the request to /chart/CheckEmployee is returning a 404 error.

You'll also need to correct your action to return the appropriate data to be consumed by the DataTables.net plugin.
 
Share this answer
 
Comments
silantmagicbbb 7-Aug-20 7:13am    
Can you explain with an example of my code
Richard Deeming 7-Aug-20 7:24am    
No, because your code is incomplete.

Have a look at this series of articles for some ideas:
jQuery DataTables and ASP.NET MVC Integration - Part I[^]

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900