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);
}
}