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

133
Vistas
Alert not coming after database update C# MVC

I have a controller in my mvc which is responsible for updating database when a button is clicked. I am using entity framework for updation of data to database, my question is how to put an alert that "database updated successfully"?

below approach I am trying but the alert does not show up.

public ActionResult LookupManagementUpdate(int[] AutoID){
            DAL.SupportCenterMethods obj = new DAL.SupportCenterMethods();
            var Mode = Request.Form["ddlTables"].ToString();
            DigitalReadinessEntities entities = new DigitalReadinessEntities();
            ViewBag.TaskCompleted = 0;
            int Cnt_element = 0;
            int orderby = 1;
            foreach (int id in AutoID)
            {
                if (id == 0)
                {
                    Cnt_element++;
                    continue;
                }
                else
                {
                    var value = entities.TBL_MASTER_INTAKE_ASSIGNED_TO.Find(id);


                    value.Preference = orderby;
                    entities.SaveChanges();
                    

                    orderby += 1;
                    Cnt_element++;
                }
               
                
                    
                
            }
            if(Cnt_element==AutoID.Length)
            { 
                ViewBag.TaskCompleted = 1;
                ViewBag.cmp = "Row Ordering completed";
            }
            
            if (Mode != "")
            {
                ViewBag.data = obj.GetLookUpTableData(Convert.ToInt32(Mode));
                ViewData["Tables"] = new SelectList(obj.GetLookUpTables(0).ToList(), "Mode", 
                "tablename", Mode);
            }
            return View("LookUpManagement");
        }

This is the logic used in above controller

 if(Cnt_element==AutoID.Length)
                { 
                    ViewBag.TaskCompleted = 1;
                    ViewBag.cmp = "Row Ordering completed";
                }

I had set a counnter and if the database updation is completed ViewBag.cmp will have the alert message in it.

In view:

<script type="text/javascript">
    $(function () {
    alert(ViewBag.cmp);});
    </script>

but nothing shows up when the updation is completed.

Please help to rectify the code or provide any alternative you are aware of...

about 4 years ago · Juan Pablo Isaza
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