I have this in my cshtml file
<div class="login">
@await Html.PartialAsync("_Login")
</div>
<div class="register">
@await Html.PartialAsync("_Register")
</div>
And my partials look like this
_Login:
@using Microsoft.AspNetCore.Identity
@using project.Models
@model LoginViewModel
@inject SignInManager<ApplicationUser> SignInManager
@inject UserManager<ApplicationUser> UserManager
<form asp-controller="Account" asp-action="Login" asp-route-returnurl="@ViewData["ReturnUrl"]" method="post" class="form-horizontal">
...
<button id="loginBtn" type="submit" class="btn btn-default">Log in</button>
</form>
_Register:
@using Microsoft.AspNetCore.Identity
@using project.Models
@model RegisterViewModel
@inject SignInManager<ApplicationUser> SignInManager
@inject UserManager<ApplicationUser> UserManager
<form asp-controller="Account" asp-action="Register" asp-route-returnurl="@ViewData["ReturnUrl"]" method="post" class="form-horizontal">
...
<button id="registerBtn" type="submit" class="btn btn-default">Register</button>
</form>
My idea is to have one of the two divs always with display:none (Initially it's the second one with this property), so the user interacts with only one form at a time. However, when I click the button [Log In] I get this error:
InvalidOperationException: The model item passed into the ViewDataDictionary is of type 'cartoondrawme.Models.AccountViewModels.LoginViewModel', but this ViewDataDictionary instance requires a model item of type 'cartoondrawme.Models.AccountViewModels.RegisterViewModel'.
My question is, do I have a flaw and what is it, or is this method entirely wrong, in which case - what is the right way?
I don't understand how the submit button from one form triggers the other form. If I delete the second div, it works fine.
Thank you.