Alert on condition in Controller Asp Net MVC

Asked

Viewed 250 times

0

Good evening, I tried looking in other posts and 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 tried several ways to put a message in case the condition gets in the IF, to display an alert message to the user, but I can’t. I tried with Tempdata but showed written only, wanted an alert or Pop Up alert. I tried last with Modelstate and put the @Html.Validationsummary() in the view, but it also didn’t show Pop-Up. I tried with Flashmessage and I couldn’t either. Can someone please help me?

1 answer

0

You can check the modelstate or anything else you want at view and call javascript Alert

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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.