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

Prop `className` did not match in next js app

I have written a sample code ( Github Link here ). this is a simple next js app, but giving me error when I refresh the page. This seems to be the common problem and I tried the fix provided in the internet but does not seem to fix my issue. The error is Warning: Prop className did not match. Server: "MuiBox-root MuiBox-root-1" Client: "MuiBox-root MuiBox-root-2". Did changes for _document.js, modified _app.js as mentioned in official website and solutions in stackoverflow. but nothing seems to work. Could someone take a look and help me whats wrong with the code? Via Active questions tagged javascript - Stack Overflow https://ift.tt/2FdjaAW

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