我正在尝试使用电子邮件登录。它应该替换Login/Signup
并在其中显示电子邮件。
它应与电子邮件位于同一布局页面。我可以在模型LoginViewModel model, string returnUrl
中看到该值,但returnUrl为空。
我没有足够的想法来解决此问题。谁能帮我。
帐户控制器
// POST: /Account/Login
[HttpPost]
[AllowAnonymous]
[ValidateAntiForgeryToken]
public async Task<ActionResult> Login(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);
}
}
Login.cshtml
<div class="col-md-4">
@using (Html.BeginForm("Login", "Account", new { ReturnUrl = ViewBag.ReturnUrl }, FormMethod.Post, new { @class = "form-horizontal", role = "form" }))
{
@Html.AntiForgeryToken()
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
<div class="card card-body">
<form action="#">
<div class="form-group">
<label for="email">Mobile Number / Email ID</label>
@Html.TextBoxFor(m => m.Email, new { @class = "form-control form-control-sm", placeholder = "Mobile Number / Email ID" })
@Html.ValidationMessageFor(m => m.Email, "", new { @class = "text-danger" })
</div>
<div class="form-group">
<label for="password">Password</label>
@Html.PasswordFor(m => m.Password, new { @class = "form-control form-control-sm password-input", placeholder = "Password" })
@Html.ValidationMessageFor(m => m.Password, "", new { @class = "text-danger" })
</div>
<div class="form-group">
<input type="checkbox" name="remember-password" checked>
<label for="">remember me for 30 days</label><span class="float-right forgot-pass"> <a href="#">forgot Password?</a></span>
</div>
<div class="form-group">
<input type="checkbox" name="remember-password" id="remember-pass-check">
<label for="">Login with OTP instead of password</label>
</div>
<div class="form-group">
<input type="submit" value="Login" class="btn btn-primary btn-block">
</div>
_Layout
<div class="row d-flex align-items-center">
<div class="col-md-5 col-sm-6 col-6 d-flex align-items-center">
<i class="fa fa-bars fa-2x menu-btn mr-3"></i>
<div class="logo">
<a href="@Url.Action("Index", "Home")" id="main-logo">
<img class="img-fluid" src="~/Content/images/logo-white.png" alt="">
</a>
</div>
</div>
<div class="col-md-7 col-sm-6 col-6 second-col d-flex align-items-center">
<li>
@Html.ActionLink("Login / Signup", "Login", "Account", null, new { @class = "btn btn-outline-primary ml-3" })
</li>
</div>
</div>
</div>
</nav>
<div class="body-content">
@RenderBody()
</div>