c# – Como recarregar a página após clicar em “ok” no alert em ASP.NET MVC


Olá. Estou usando o View.Bag para exibir um “pop up”, mas o problema é que, quando clico em “OK”, a página não é atualizada. Existe alguma maneira de verificar se eu cliquei no botão?

Obrigado a quem me ajudar.

Meu Codigo:

Index.cshtml

@model RecuperarConta.Controllers.User
@using Newtonsoft.Json

@{
    ViewBag.Title = "Home Page";
}

<html>
<head>
    <script>

        // functions used to decrease time
        // if time runs out, a method is called that changes the user's state to true
        // and update the page so that a message appears saying that the link is no longer available
        function startCountdown(timeLeft) {

            var interval = setInterval(countdown, 1000);

            update();

            function countdown() {

                if (--timeLeft > 0) {
                    update();
                } else {
                    clearInterval(interval);
                    update();
                    completed();
                }
            }

            function update() {
                hours = Math.floor(timeLeft / 3600);
                minutes = Math.floor((timeLeft % 3600) / 60);
                seconds = timeLeft % 60;

                document.getElementById('time-left').innerHTML = '' + minutes + ':' + seconds;
            }

            function completed() {

                $.ajax({
                    type: 'POST',
                    url: 'Home/MyAction',
                    data: {},
                    success: function (response) {
                        window.location.href = response.redirectToUrl;
                    }
                });
            }
        }
    </script>
</head>
<body onload="startCountdown(600);">

    <p style="text-align:right;margin-right:100px;font-size:20px">Redirect in <span id="time-left"></span></p>


    @using (Html.BeginForm("Index", "Home", FormMethod.Post, new { enctype = "multipart/form-data" }))
    {

        @Html.AntiForgeryToken();


        @*@Html.HiddenFor(model => model.email)*@

        <div class="form-group" style="text-align:center">
            <h4>Please enter a new password</h4><br />
            @*@Html.LabelFor(model => model.password, htmlAttributes: new { @class = "control-label col-md-2" })*@
            <h5>Enter Password</h5>

            @*@Html.EditorFor(model => model.password, new { htmlAttributes = new { @id = "password", placeholder = "Password", Type = "password", pattern = "/d{7}", title = "Password must be at least 7 characters" } })*@
            @Html.EditorFor(model => model.password, new { htmlAttributes = new { @id = "password", placeholder = "Password", Type = "password" } })


            @Html.ValidationMessageFor(model => model.password, "", new { @class = "text-danger" })
        </div>

        <div class="form-group" style="text-align:center">
            @*@Html.LabelFor(model => model.password1, htmlAttributes: new { @class = "control-label col-md-2" })*@
            <h5>Confirm Password</h5>
            @Html.EditorFor(model => model.password1, new { htmlAttributes = new { @id = "password1", placeholder = "Password", Type = "password" } })
            @Html.ValidationMessageFor(model => model.password1, "", new { @class = "text-danger" })

        </div>

        <br />
        <div class="form-group" style="text-align:center">
            <input type="submit" id="btn_Update" value="Change Password" class="btn btn-default" />
        </div>


        <div class="modal" id="popup">
            <div class="modal-dialog">
            </div>
            <div class="modal-body">
                <p>asa asfasfas</p>
            </div>
            <div class=" modal-footer">
                <div class="form-group" style="text-align:center">
                    <input type="submit" value="OK" class="btn btn-default" />
                </div>
            </div>
        </div>

    }

    @* will show the pop up if the passwords are not the same *@

    @if (ViewBag.Message != null)
    {
        <script type="text/javascript">
            window.onload = function () {

               alert("@ViewBag.Message");

            };

        </script>
    }


     @*< !--jQuery library-- >*@
     <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
     <script src="js/bootstrap.js"></script>

    </body>
</html>

Controller

    (NoCache)
    (HttpPost)
    (ValidateAntiForgeryToken)
    public async Task<ActionResult> Index((Bind(Include = "email,password,password1")) User user)
    {
        user.uid = "";

        User user1 = TempData("user") as User;

        if (user1 != null)
            user.email = user1.email;


        // if passwords are different
        // then shows a pop up
        if (user.password != user.password1)
        {
             ViewBag.Message = "Passwords do not match";
             return View(user);
        }

        //if the fields are empty
        if (user.password == null || user.password1 == null)
        {
            ViewBag.Message = "Empty fields";
            return View(user);
        }

    }

Minha pagina com o pop up

inserir a descrição da imagem aqui