How do I keep a modal open after a RedirectToAction in the view?

0

I have a registration form in a modal, in this modal I have a google reCaptcha that if it is not valid it should display the message "Invalid or mandatory google captcha!" clicking the record button. My difficulty is, how to keep this modal open after giving a RedirectToAction in partial view.

Here is my controller:

        // POST: /Account/Register
        [HttpPost]
        [AllowAnonymous]
        [ValidateAntiForgeryToken]
        [CaptchaValidator(PrivateKey = "---minha chave---")]
        public async Task<ActionResult> Register(RegisterViewModel model, bool captchaValid)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var user = new ApplicationUser
                    {
                        NomeCompleto = model.NomeCompleto,
                        UserName = model.Email,
                        Email = model.Email,
                        EmpresaNome = model.EmpresaNome,
                        Telefone = model.Telefone,
                        PrimeiroAcesso = 1
                    };
                    var result = await UserManager.CreateAsync(user, model.Password);
                    if (result.Succeeded)
                    {
                        string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);
                        var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
                        await ServicoEmail.Execute(model.Email, "Confirme a sua conta", "<b>Olá" + " " + model.NomeCompleto + "</b>" + "!</br> Agradecemos por registrar uma conta no Ebase Emissor de NF-e e NFC-e! Antes de começarmos, precisamos confirmar que é você mesmo. Clique <a href=\"" + callbackUrl + "\">AQUI</a> para verificar seu endereço de e-mail! ");
                        //Session["NomeUsuario"] = ApplicationUser.GetUserByName().NomeCompleto;

                        ViewBag.Message = "Verifique o seu email e confirme a sua conta, você tem que confirmar a sua conta antes de fazer o login!";
                        return View("Info");
                    }                   
                }
                // If we got this far, something failed, redisplay form
                if (!captchaValid)
                {
                    TempData["mensagemErroRegister"] = "Captcha do google inválido ou obrigatório!";
                    return View("_ExperimenteGratis", "Home");
                }
                ViewBag.Message = "Ocorreu um erro ao fazer seu Registro! Tente Novamente!";
                return View("InfoEmail");
            }
            catch (Exception)
            {
                return View("ErrorLogin");
            }
        }

Here is the section where I have my modal that is located in the Login view:

<div id="modal-registro" class="modal fade  col-md-12" role="dialog">
        <div class="modal-dialog">
            <div class="modal-content  col-md-12">

                <div class="modal-body">
                    <h4 class="iq-tw-7 iq-mb-20" align="center">Experimente grátis nosso sistema por 7 dias</h4>

                    <div class="form-group">
                        <div id="ajaxloader" style="display:none"><img class="center-block mt-30 mb-30" src="~/Content/images/ajax-loader.gif" alt="#"></div>
                    </div>
                    @using (Html.BeginForm("Register", "Account", FormMethod.Post))
                    {
                        @Html.AntiForgeryToken()
                        @Html.Partial("_ExperimenteGratis", null)

                        if (TempData["mensagemErroRegister"] != null)
                        {
                            <div class="field-error text-danger">
                                @TempData["mensagemErroRegister"]
                            </div>
                        }
                        <div class="text-left recaptchaRegistroModal">
                            @Html.Recaptcha()
                            @Html.ValidationMessage("ReCaptcha")
                        </div>
                        <div class="text-right col-md-12">
                            <input type="submit" class="button btn-danger" value="Registrar" style="margin-bottom:20px" />

                        </div>
                    }
                </div>
            </div>

        </div>
    </div>

And even though I did not find it so necessary I decided to include all of my partial view that is opened within the modal:

@model Ebase.EmissorNFeWeb.ViewModels.RegisterViewModel
@{
    Layout = null;
}

<script src="~/Scripts/jquery-3.2.1.js"></script>
<script src="~/Scripts/jquery.validate.js"></script>
<script src="~/Scripts/jquery.validate.unobtrusive.js"></script>
<script src="~/Scripts/jquery.mask.js"></script>


<div class="contact-form">
    @Html.ValidationSummary(true)

    <div class="col-md-12">
        <label>Seu Email </label>
        @Html.TextBoxFor(m => m.Email, new { @class = "form-control input-lg" })
        @Html.ValidationMessageFor(m => m.Email, "", new { @class = "text-danger input-lg" })
    </div>
</div>
<div class="contact-form">
    <div class="col-md-12">
        <label>Seu Nome Completo </label>
        @Html.TextBoxFor(m => m.NomeCompleto, new { @class = "form-control input-lg" })
        @Html.ValidationMessageFor(m => m.NomeCompleto, "", new { @class = "text-danger input-lg" })
    </div>
</div>
<div class="contact-form">
    <div class="col-md-12">
        <label>Nome da Sua Empresa </label>
        @Html.TextBoxFor(m => m.EmpresaNome, new { @class = "form-control input-lg" })
        @Html.ValidationMessageFor(m => m.EmpresaNome, "", new { @class = "text-danger input-lg" })
    </div>
</div>
<div class="contact-form">
    <div class="col-md-12">
        <label>Telefone com DDD </label>
        @Html.EditorFor(m => m.Telefone, new { htmlAttributes = new { @id = "telefone", @class = "form-control input-lg" } })
        @Html.ValidationMessageFor(m => m.Telefone, "", new { @class = "text-danger  input-lg", @id = "telefone" })
    </div>
</div>
<div class="contact-form">
    <div class="col-md-12">
        <label>Sua Senha </label>
        @Html.PasswordFor(m => m.Password, new { @class = "form-control input-lg" })
        @Html.ValidationMessageFor(m => m.Password, "", new { @class = "text-danger input-lg" })
    </div>
</div>
<div class="contact-form">
    <div class="col-md-12">
        <label>Confirme sua Senha </label>
        @Html.PasswordFor(m => m.ConfirmPassword, new { @class = "form-control input-lg" })
        @Html.ValidationMessageFor(m => m.ConfirmPassword, "", new { @class = "text-danger input-lg" })
    </div>
</div>


<script type="text/javascript">
    $(document).ready(function () {
        $("#telefone").mask("(99)99999-9999");
    });
</script>

Note: Remembering that I know of the possibility of doing this using AJAX.BeginForm, so what I want to know is there is another way to do this! / em>

    
asked by anonymous 06.06.2018 / 19:37

0 answers