I have a login page. This login page contains a register Partial view and a login partial view. Everything is showing up Ok.
Here is my controller for that page.
public ActionResult Login(string returnUrl)
{
var model = new AccountPageViewModel();
model.LoginModel = new LoginViewModel();
model.RegisterModel = new RegisterViewModel();
return View(model);
}
where I run into issues is posting from the partials and trying to return the model that I just posted, when there are errors in the model state.
Here is what my Login partial is posting to.
public async Task<ActionResult> _LoginPartial(LoginViewModel model, string returnUrl)
{
if (!ModelState.IsValid)
{
return View(model)
}
// This doesn't count login failures towards account lockout
// To enable password failures to trigger account lockout, change to shouldLockout: true
var result = await SignInManager.PasswordSignInAsync(model.Email, model.Password, model.RememberMe, shouldLockout: false);
switch (result)
{
case SignInStatus.Success:
return RedirectToLocal(returnUrl);
case SignInStatus.LockedOut:
return View("Lockout");
case SignInStatus.RequiresVerification:
return RedirectToAction("SendCode", new { ReturnUrl = returnUrl, RememberMe = model.RememberMe });
case SignInStatus.Failure:
default:
ModelState.AddModelError("", "Invalid login attempt.");
return View(model);
}
}
Can someone explain how I would post from the Login partial, to a controller action and then return the data to the partialView rather than returning to the main Login view? I can't seem to find the answer.
Thanks.