I have a Partial view that contains a form ajax in Asp.net core 2.0.
You can see Partial View named _loginPartial
@model partialView.Models.LoginViewModel
<div id="login">
<form asp-controller="Account" asp-action="Login" id="frmLogin" data-ajax="true" data-ajax-method="POST" data-ajax-update="#frmLogin" data-ajax-mode="Replace">
<div id="login">
<div class="form-group">
<input asp-for="UserName" class="form-control" />
<span asp-validation-for="UserName"></span>
</div>
<div class="form-group">
<input asp-for="Password" class="form-control" />
<span asp-validation-for="UserName"></span>
</div>
<div class="form-group pull-left ">
<button type="submit" class="btn btn-success">Submit</button>
</div>
</div>
</form>
When i submit form to /Account/Login everything is ok, but after login i want to redirect to another view in another Area
[HttpPost]
public async Task<IActionResult> Login(LoginViewModel model)
{
if (ModelState.IsValid)
{
//Success Login
return Redirect("/AdminPanel/Home/Index");
}
else
{
//if ModelState is invalid
}
//if UserName Or Password is incorrect
return PartialView("_loginpartialView", model);
}
And here is LoginViewModel
public class LoginViewModel
{
[Display(Name = "UserName")]
[Required(AllowEmptyStrings = false, ErrorMessage = "Please Enter UserName")]
public string UserName { get; set; }
[Display(Name = "Password")]
[Required(AllowEmptyStrings = false, ErrorMessage = "Please Enter Password")]
[DataType(DataType.Password)]
public string Password { get; set; }
}
Also i use this code to Show Partial View in index
@Html.Partial("_loginpartialView")
But there is a problem. After success login new view replace with Partial view.In other words, it does not navigate to /AdminPanel/Home/Index and new View replace with Partial View, How can i navigate to another view in this case?
ModelStatenot valid in partial view