Why does not this jquery code work for DataTable in Asp.Net Mvc

1

I'm trying to show the data in the DataTable format and it does not work for me here, I pass the code to it.

@{
    ViewBag.Title = "GetData";
}

<h2>Employee CRUD Operations</h2>

<table id="employeeTable" class="table table-striped table-bordered">
    <thead>
        <tr>
            <th>id_contrato</th>
            <th>responsable</th>
            <th>titulo</th>
            <th>descripcion</th>
            <th>inicio</th>
            <th>vigencia</th>
            <th>monto</th>
            @*<th>Description</th>
            <th>Description</th>*@
        </tr>
    </thead>
</table>


<link href="https://cdn.datatables.net/1.10.16/css/dataTables.bootstrap4.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.16/js/dataTables.bootstrap4.min.js"></script>

 
    <script>
        $(document).ready(function () {
            dataTable = $("#employeeTable").DataTable({
                "ajax": {
                    "url":"/contratos_data/GetData",
                    "type": "GET",
                    "datatype": "Json"
                },

                "columns": [
                    { data: "id_contrato" },
                    { data: "responsable" },
                    { data: "titulo" },
                    { data: "descripcion" },
                    { data: "inicio" },
                    { data: "vigencia" }, 
                    { data: "monto" }
                    //{ "data": "Categorycontract.Description" },
                    //{ "data": "Departament.Description" }
                ]
                //"serverSide": "true",
                //"order":[0,"asc"]
                 });
            });
    </script>

}
 
public JsonResult GetData()
        {
            using (Contratos_JuridicaContext db = new Contratos_JuridicaContext())
            {
                //List<contratos_data> contra = db.contratos_data.ToList<contratos_data>();
                var contra = db.contratos_data.ToList();
                return Json(new { data = contra }, JsonRequestBehavior.AllowGet);
            }
        }

    
asked by Mairon Mariñez 05.12.2017 в 17:46
source

1 answer

0

After the last <th> put another empty example:

      <tr>
        <th>id_contrato</th>
        <th>responsable</th>
        <th>titulo</th>
        <th>descripcion</th>
        <th>inicio</th>
        <th>vigencia</th>
        <th>monto</th>           
        <th></th>
      </tr>

that <th> empty datatable uses it for the search box and if it is not defined sometimes the table is not shown. Nor do I see defined the <tbody>

    
answered by 05.12.2017 в 19:08