I am using Asp.Net identity logic module for authentication process. I am using this theme for login and signup and external logins all in one view.
Here is my Login.cshtml view that contain social login, register and login partials
@using Helping.ViewModels
@{
ViewBag.Title = "Log in";
}
<div class="container">
<div class="row">
<br />
<br />
<div class="col-lg-4">
<div>
<section id="socialLoginForm">
@Html.Partial("_ExternalLoginsListPartial", new ExternalLoginListViewModel { Action = "ExternalLogin", ReturnUrl = ViewBag.ReturnUrl })
</section>
</div>
</div>
<div class="col-lg-4">
<h2><b>Sign Up</b></h2>
<hr />
@Html.Partial("Register")
</div>
<div class="col-lg-4">
<h2><b>Log In</b></h2>
<hr />
@Html.Partial("LocalLogin")
</div>
</div>
</div>
@section Scripts {
@Scripts.Render("~/bundles/jqueryval")
}
LocalLogin and Register are the strongly typed partial views.Problem is that when I try to Login with a user that doesnot exist it returns the model , here is the action
public async Task<ActionResult> Login(LoginViewModel model, string returnUrl)
{
if (ModelState.IsValid)
{
var user = await UserManager.FindAsync(model.UserName, model.Password);
if (user != null)
{
if (!await UserManager.IsEmailConfirmedAsync(user.Id))
{
string callbackUrl = await SendEmailConfirmationTokenAsync(user.Id, "Confirm your account-Resend");
ViewBag.errorMessage = "You must have a confirmed email to log on.";
return View("Error");
}
else
{
await SignInAsync(user, model.RememberMe);
return RedirectToLocal(returnUrl);
}
}
else
{
ModelState.AddModelError("", "Invalid username or password.");
}
}
// If we got this far, something failed, redisplay form
return View(model);
}
It return following error The model item passed into the dictionary is of type 'Helping.ViewModels.LoginViewModel', but this dictionary requires a model item of type 'Helping.ViewModels.RegisterViewModel'.
My Register view expects RegisterViewModel and My LocalLogin expects LoginViewModel
@using Helping.ViewModels
@model LoginViewModel
@model HelpingHands.ViewModels.RegisterViewModel
How to provide both the models with one view need help ?