Refresh only on parial view

0

I want the user at some point to be logged in to continue scheduling, so I'm opening a login mode, which does the whole login part, so when I return to the screen, the login does not update the information, needed a refresh in this partial view to view the data of the logged in user:

Jquery from my index page where things are happening:

 $("#btnLogin").click(function () {
        var emailModal = $("#txtEmail").val();
        var senhaModal = $("#txtSenha").val();
        var remembermeModal = false;


         $.ajax({
            url: "/Agendamento/LoginModal",
            type: "POST",
            data: {
                "email": emailModal,
                "senha": senhaModal,
                "rememberme": remembermeModal

            },
            success: function (data) {
                $("#LoginTeste").html(data);
            }
        })

Controller

public async Task<IActionResult> LoginModal(string email, string senha, bool rememberme)
    {
        var model = new AgendamentoViemModel();

        model.Login.Email = email;
        model.Login.Password = senha;
        model.Login.RememberMe = rememberme;


        if (model.Login.Email.IndexOf('@') > -1)
        {
            //Validate email format
            string emailRegex = @"^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}" +
                                   @"\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\" +
                                      @".)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$";
            Regex re = new Regex(emailRegex);
            if (!re.IsMatch(model.Login.Email))
            {
                ModelState.AddModelError("Email", "Email is not valid");
            }
        }
        else
        {
            //validate Username format
            string emailRegex = @"^[a-zA-Z0-9]*$";
            Regex re = new Regex(emailRegex);
            if (!re.IsMatch(model.Login.Email))
            {
                ModelState.AddModelError("Email", "Username is not valid");
            }
        }


        if (ModelState.IsValid)
        {
            var userName = model.Login.Email;
            if (userName.IndexOf('@') > -1)
            {
                var user = await _userManager.FindByEmailAsync(model.Login.Email);
                if (user == null)
                {
                    ModelState.AddModelError(string.Empty, "Invalid login attempt.");
                    return View(model);
                }
                else
                {
                    userName = user.UserName;
                }
            }

            var result = await _signInManager.PasswordSignInAsync(userName, model.Login.Password, model.Login.RememberMe, lockoutOnFailure: false);

            if (result.Succeeded)
            {
                _logger.LogInformation("User logged in.");
                return PartialView("_LoginPartial", model);


            }
            else
            {
                return new StatusCodeResult(400);
            }

        }


        return View(model);
    }

Excerpt from where the partial view is rendered on the Layout.cshtml page:

  <div id="LoginTeste">
                @await Html.PartialAsync("_LoginPartial")
                <div>

                </div>
            </div>

I want to update this information, does anyone know how?

    
asked by anonymous 12.05.2018 / 22:02

0 answers