更新: 将数据发送到控制器并从控制器获取数据时我不知道为什么要显示html源代码,
这是我的登录视图
<section id="form">
<!--form-->
<div class="container">
<div class="row">
<div class="col-sm-4 col-sm-offset-1">
@{ Html.RenderPartial("_Signup", new ViewDataDictionary());}
</div>
<div class="col-sm-1">
<h2 class="or">or</h2>
</div>
<div class="col-sm-4">
@Html.Partial("_login")
</div>
</div>
</div>
当你看到两个局部视图时,一个用于登录,一个用于在一个视图中注册, 如果用户没有在登录部分注册或输入错误的密码并在登录按钮上点击,从服务器返回,浏览器显示登录页面的基本html代码,下面有我的控制器和我的部分视图
<section id="loginForm">
@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="form-group">
<div class="col-md-12">
@Html.TextBoxFor(m => m.Email, new { @class = "form-control", placeholder ="Email" })
@Html.ValidationMessageFor(m => m.Email, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
<div class="col-md-12">
@Html.PasswordFor(m => m.Password, new { @class = "form-control", placeholder = "password" })
@Html.ValidationMessageFor(m => m.Password, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.RememberMe, htmlAttributes: new { @class = "control-label col-md-4" })
<div class="col-md-8">
<div class="checkbox">
@Html.EditorFor(model => model.RememberMe)
@Html.ValidationMessageFor(model => model.RememberMe, "", new { @class = "text-danger" })
</div>
</div>
</div>
<div class="form-group">
<div class="pull-right col-md-3">
<input type="submit" value="login" class="btn btn-default" style="background-color:#5d1338;color:white" />
</div>
</div>
}
</section>
并在我的掌控之中
[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:
MigrateShoppingCart(model.Email);
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("Login",model);
}
}
答案 0 :(得分:0)
根据我的理解,您只想返回Login html&#34; view&#34;当登录请求失败时。
为什么不为此目的创建新的查看,并在 SignInStatus.Failure 的情况下返回