Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

138
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda