I dont get any errors in the console. And the breakpoint in the method of the controller is never called. (sorry for my bad english). The problem is that the method is never called from the ajax. Please help.
Html:
<!-- Modal -->
<div id="modal-inclusion" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="exampleModalCenterTitle" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered" role="document">
<div class="modal-content">
<div class="modal-header">
<h2 class="modal-title text-center" id="exampleModalCenterTitle">Solicitar inclusión</h2>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<!-- Header -->
<div class="card-header">
<div class="row justify-content-between align-items-center flex-grow-1">
<div class="col-12 col-md">
<div class="d-flex justify-content-between align-items-center">
<h5 class="card-header-title">Users</h5>
</div>
</div>
<div class="col-auto">
<!-- Filter -->
<form>
<!-- Search -->
<div class="input-group input-group-merge input-group-flush">
<div class="input-group-prepend input-group-text">
<i class="bi-search"></i>
</div>
<input id="datatableWithSearchInput" type="search" class="form-control" placeholder="Search users" aria-label="Search users">
</div>
<!-- End Search -->
</form>
<!-- End Filter -->
</div>
</div>
</div>
<!-- Table -->
<div class="table-responsive datatable-custom">
<table id="tb_renovaciones_inclusion js-datatable table table-borderless table-thead-bordered table-nowrap table-align-middle card-table"
data-hs-datatables-options='{
"order": [],
"search": "#datatableWithSearchInput",
"isResponsive": false,
"isShowPaging": false,
"pagination": "datatableWithSearchPagination"
}'>
<thead class="thead-light">
<tr>
<th scope="col">Poliza</th>
<th scope="col">Tipo</th>
<th scope="col">Vigencia</th>
<th scope="col">Inclusión</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
</div>
<!-- End Table -->
<!-- Footer -->
<div class="card-footer">
<!-- Pagination -->
<div class="d-flex justify-content-center justify-content-sm-end">
<nav id="datatableWithSearchPagination" aria-label="Activity pagination"></nav>
</div>
<!-- End Pagination -->
</div>
<!-- End Footer -->
</div>
<div class="modal-footer">
<button type="button" class="btn btn-white" data-bs-dismiss="modal">Cancelar</button>
<button type="button" class="btn btn-primary" data-bs-dismiss="modal">Cerrar</button>
</div>
</div>
</div>
</div>
<!-- End Modal -->
Javascript:
<script>
(function(){
console.log("Se hace la llamada al controlador")
$('#tb_renovaciones_inclusion').DataTable({
"destroy": true, //Para destruir la inicializacion del init
"order": [[3, "asc"]], // asc y desc - ya no xq no lo estoy ordenando en el store procedure sql
"paging": false, // Para que te muestre todo los valores
"isResponsive": false, // Falta averiguar que realiza
"isShowPaging": false, // Falta averiguar que realiza
"sScrollY": "100%", // Tiene que ver con el scroll de la tabla
"sScrollX": false, // Tiene que ver con el scroll de la tabla
"ajax": {
"url": "@Url.Action("ListarRenovacionesTotales", "JsonConexion")",
"type": "GET",
"datatype": "json"
},
"columns": [
{
"render": function (data, type, full, meta) {
console.log(full);
return '<td><span class="d-block text-primary text-center">' + full.numeroPoliza + '</span><span class="badge bg-soft-info text-info d-flex text-center justify-content-center align-items-center">' + full.descripcionCortoRamo + '</span></td>';
}
},
{
"render": function (data, type, full, meta) {
return '<td><span class="d-block mb-0 h5">' +full.tipoVigencia+ '</span><span class="d-block fs-5">' +full.formaPagoPrima+ '</span></td>';
}
},
{
"render": function (data, type,full, row) {
return '<td><span class="d-block mb-0"> I: ' + full.vigenciaInicio+ '</span><span class="d-block fs-5"> F: ' + full.vigenciaFin+ '</span></td>';
}
},
{
"render": function (data, type, full, meta) {
return '<td><a class="justify-content-center d-flex align-items-center" href="/Cliente/renovar-poliza-riesgos-humanos?id=' + full.id_Poliza+'"><i class="fs-2 fa-solid fa-repeat" style = "color: #0700C9;" ></i></a></td>';
}
},
// { "data": "msjEnviados" },
]
});
console.log("el método ya se ejecutó")
})()
</script>
Controller:
[HttpGet]
public JsonResult ListarRenovacionesTotales()
{
string userName = _httpContextAccessor.HttpContext?.User?.Identity?.Name; //ID USUARIO
DetalleUsuarioDA detalleUsuarioDA = new DetalleUsuarioDA();
DetalleUsuario detalleUsuario = detalleUsuarioDA.GetDetalleUsuario(userName);
List<QueryPolizaPrimaViewModel> lista = new List<QueryPolizaPrimaViewModel>();
var polizaDA = new PolizaDA();
lista = polizaDA.ListarPolizaPrimaClienteSctr(detalleUsuario.Fk_Cliente).ToList();
if (lista.Count > 0)
{
return Json(new
{
data = lista.Select(item => new {
Id_Poliza = item.Id_Poliza,
Fk_Cliente = item.Fk_Cliente,
NumeroPoliza = item.NumeroPoliza,
Fk_Ramo = item.Fk_Ramo,
VigenciaInicio = item.VigenciaInicio.ToString("dd/MM/yyyy"),
VigenciaFin = item.VigenciaFin.ToString("dd/MM/yyyy"),
DocumentoPrima = item.DocumentoPrima,
FormaPagoPrima = item.FormaPagoPrima,
PrimaNeta = item.PrimaNeta,
ImporteComisionBroker = item.ImporteComisionBroker,
Moneda = item.Moneda,
EstadoPoliza = item.EstadoPoliza,
Asegurado = item.Asegurado,
TipoVigencia = item.TipoVigencia,
DescripcionCortoRamo = item.DescripcionCortoRamo,
})
});
}
else
{
// Si la lista está vacía, retorna un mensaje de error
return Json(new { data = "lista-vacia" });
}
}
I tried put breakpoints and use console.log(full) but that does not working.
Via Active questions tagged javascript - Stack Overflow https://ift.tt/bKe6CYR
Comments
Post a Comment