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

Confusion between commands.Bot and discord.Client | Which one should I use?

Whenever you look at YouTube tutorials or code from this website there is a real variation. Some developers use client = discord.Client(intents=intents) while the others use bot = commands.Bot(command_prefix="something", intents=intents) . Now I know slightly about the difference but I get errors from different places from my code when I use either of them and its confusing. Especially since there has a few changes over the years in discord.py it is hard to find the real difference. I tried sticking to discord.Client then I found that there are more features in commands.Bot . Then I found errors when using commands.Bot . An example of this is: When I try to use commands.Bot client = commands.Bot(command_prefix=">",intents=intents) async def load(): for filename in os.listdir("./Cogs"): if filename.endswith(".py"): client.load_extension(f"Cogs.{filename[:-3]}") The above doesnt giveany response from my Cogs ...

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

Where and how is this Laravel kernel constructor called? [closed]

Where and how is this Laravel kernel constructor called? public fucntion __construct(Application $app, $Router $roouter) { } I have read the documentation and some online tutorial but I can find any clear explanation. I am learning Laravel and I am wondering where does this kernel constructor receives its arguments from. "POSTMOTERM" CLARIFICATION: Here is more clarity.I have checked the boostrap/app.php and it is only used for boostrapping the interfaces into the container class. What is not clear to me is where and how the Kernel class is instatiated and the arguments passed to the object calling the constructor.Something similar to; obj = new kernel(arg1,arg2) or, is the framework using some magic functions somewhere? Special gratitude to those who burn their eyeballs and brain cells on this trivia before it goes into a full blown menopause alias "MARKED AS DUPLICATE". To some of the itchy-finger keyboard warriors, a.k.a The mods,because I believe in th...