Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

371
Vistas
ASP.net Core MVC : How to fix looped results?

I have a problem when saving items on my application, items are listed from a table. Everytime I save the updated items , the items tend to loop after saving.

This is my event of the button.

$('#saveEventBTN').click(function (event) {
        //EventManager.SaveEventBYApprover();
        EventManager.MultipleSave();
        event.preventDefault();
    }); 

This one is from the .Change event on the dropdown menu where I can enter the ids in the arrays that I will use for the looping saving transaction.

  $("#tableApprovalState" + idEvent + "").change(function (event) {
            idApproveStatus = $("#tableApprovalState" + idEvent + "").val();
            event.preventDefault();

      // Adding the event into an array for multiple selection.
            if (idEventMulti.indexOf(idEvent) !== -1)
            {
                var del = idEventMulti.indexOf(idEvent);
                idEventMulti.splice(del, 1);
                idApproveStatusMulti.splice(del, 1);

                idEventMulti[idEventMulti.length] = idEvent;
                idApproveStatusMulti[idApproveStatusMulti.length] = idApproveStatus;
            } else {
                idEventMulti[idEventMulti.length] = idEvent;
                idApproveStatusMulti[idApproveStatusMulti.length] = idApproveStatus;
            }
        });

This are the functions on my module :

This only loops the global array variable for the ids of the array.

EventManager.MultipleSave = function () {
    for (let i = 0; i < idEventMulti.length; i++) {
        EventManager.SaveEventBYApprover(idEventMulti[i], idApproveStatusMulti[i]);
    }
}

This one is the Ajax call to save:

EventManager.SaveEventBYApprover = function (idevent, ideventstatus) {
    $.ajax({
        url: "/Modules/SaveEvent",
        type: "POST",
        data: {
            IdEvent: idevent,
            IdEventStatus: ideventstatus,
            LastModifiedBy: user
        },
        dataType: "json",
        success: function (data) {
            $("#successMsg").html("").html(data.msg);
            $("#successConfirmModal").modal("show");
      
            searchResultsTable.clear().draw();
            EventManager.BindDataTable();   
        }
    });
}

This is how it looks like after the transactions successfully save.

enter image description here

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

I think you're correct in assuming the problem is called by multiple calls to EventManager.BindDataTable in the ajax success callbacks.

It's not a solution to call this method after the for loop in EventManager.MultipleSave, because this code will be called immediately after starting the ajax calls, which are asynchronous.

What you want is to set up some code that runs after all the asynchronous save ajax calls have completed. This is quite messy to achieve with the current callback model you're using.

Instead you can exploit that the $.ajax function returns a Promise. This means that if you return the result of $.ajax from EventManager.SaveEventBYApprover, you can collect these in an array in EventManager.MultipleSave, and then use something like:

$.when(myAjaxPromises).then(function() { 
   // code that runs after all saves goes here
}, function() {
   // error handling goes here
});
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda