Skip to main content

Ajax from DataTable is not working in .net 6

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

Popular posts from this blog

How to show number of registered users in Laravel based on usertype?

i'm trying to display data from the database in the admin dashboard i used this: <?php use Illuminate\Support\Facades\DB; $users = DB::table('users')->count(); echo $users; ?> and i have successfully get the correct data from the database but what if i want to display a specific data for example in this user table there is "usertype" that specify if the user is normal user or admin i want to user the same code above but to display a specific usertype i tried this: <?php use Illuminate\Support\Facades\DB; $users = DB::table('users')->count()->WHERE usertype =admin; echo $users; ?> but it didn't work, what am i doing wrong? source https://stackoverflow.com/questions/68199726/how-to-show-number-of-registered-users-in-laravel-based-on-usertype

Why is my reports service not connecting?

I am trying to pull some data from a Postgres database using Node.js and node-postures but I can't figure out why my service isn't connecting. my routes/index.js file: const express = require('express'); const router = express.Router(); const ordersCountController = require('../controllers/ordersCountController'); const ordersController = require('../controllers/ordersController'); const weeklyReportsController = require('../controllers/weeklyReportsController'); router.get('/orders_count', ordersCountController); router.get('/orders', ordersController); router.get('/weekly_reports', weeklyReportsController); module.exports = router; My controllers/weeklyReportsController.js file: const weeklyReportsService = require('../services/weeklyReportsService'); const weeklyReportsController = async (req, res) => { try { const data = await weeklyReportsService; res.json({data}) console...

How to split a rinex file if I need 24 hours data

Trying to divide rinex file using the command gfzrnx but getting this error. While doing that getting this error msg 'gfzrnx' is not recognized as an internal or external command Trying to split rinex file using the command gfzrnx. also install'gfzrnx'. my doubt is I need to run this program in 'gfzrnx' or in 'cmdprompt'. I am expecting a rinex file with 24 hrs or 1 day data.I Have 48 hrs data in RINEX format. Please help me to solve this issue. source https://stackoverflow.com/questions/75385367/how-to-split-a-rinex-file-if-i-need-24-hours-data