Alert upon entering condition in the Asp Net MVC Controller

0

Good evening, I tried to look in other posts and I did not find the answer. I have a Controller in my Asp Net MVC project that has this condition:

  if (resultado == null)
        {

            ModelState.AddModelError("", "Usuário ou senha inválidos");
            return RedirectToAction("Index", "Nav");

        }
        else
        {

            if (produto != null)
            {
                carrinho.AdicionarItem(prod, quantidade);
            }

            return RedirectToAction("Index", "Nav");
        }
    }

I have tried in several ways to put a message in case the condition is in the IF to display an alert message to the user, but I can not. I got to try with TempData but it displayed only written, I wanted an Alert or Pop Up Alert. I tried last with ModelState and put @ Html.ValidationSummary () in the view, but it also did not display Pop-Up. I tried with FlashMessage and I could not. Can someone please help me?

    
asked by anonymous 10.05.2018 / 05:11

1 answer

0

You can check the modelstate or whatever you want in view and call javascript alert

@if(!string.IsNullOrEmpty(ModelState.isValid)) {
    <script>alert("Mensagem de erro");</script>
}
    
07.06.2018 / 19:26