我的应用程序中有一个 LogInOrRegister 页面,它调用 2 个子操作 LogInOrRegister.cshtml
@{
ViewBag.Title = "Log in";
}
@Html.Action("Login", "Account", new { returlUrl = ViewBag.ReturnUrl})
@Html.Action("Register", new { returlUrl = ViewBag.ReturnUrl})
@section Scripts {
@Scripts.Render("~/bundles/jqueryval")
}
登录部分视图是:
@model Com.WTS.Portal.Models.LoginModel
<hgroup class="title">
<h1>@ViewBag.Title</h1>
</hgroup>
<section id="loginForm">
<h2>Use a local account to log in.</h2>
@using (Html.BeginForm(new { ReturnUrl = ViewBag.ReturnUrl })) {
@Html.AntiForgeryToken()
@Html.ValidationSummary(true)
<fieldset>
<legend>Log in Form</legend>
<ol>
<li>
@Html.LabelFor(m => m.Email)
@Html.TextBoxFor(m => m.Email)
@Html.ValidationMessageFor(m => m.Email)
</li>
<li>
@Html.LabelFor(m => m.Password)
@Html.PasswordFor(m => m.Password)
@Html.ValidationMessageFor(m => m.Password)
</li>
<li>
@Html.CheckBoxFor(m => m.RememberMe)
@Html.LabelFor(m => m.RememberMe, new { @class = "checkbox" })
</li>
</ol>
<input type="submit" value="Log in" />
</fieldset>
}
</section>
我的 AccountController.cs 包含以下代码:
[AllowAnonymous]
public PartialViewResult Login(string returnUrl)
{
ViewBag.ReturnUrl = returnUrl;
return PartialView();
}
[HttpPost]
[AllowAnonymous]
[ValidateAntiForgeryToken]
public PartialViewResult Login(LoginModel model, string returnUrl)
{
if (ModelState.IsValid && WebSecurity.Login(model.Email, model.Password, persistCookie: model.RememberMe))
{
RedirectToLocal(returnUrl);
}
// If we got this far, something failed, redisplay form
ModelState.AddModelError("", "The user name or password provided is incorrect.");
return PartialView(model);
}
我正确地看到了我获取页面 LogInOrRegister.cshtml 的 2 部分视图
当我提交表单时,如果表单中存在验证错误,则会显示视图(无布局),而不是应该作为 LogInOrRegster 一部分的部分视图
任何想法 ?