我在父页面中有两个部分视图。问题是,当表单成功提交后,当我调用重定向到本地时,下一页将加载到父级内部部分视图的位置。另一种形式也是可见的。这是与其中之一关联的操作方法和视图逻辑,因为它们几乎相同。我该如何解决?
[AllowAnonymous]
public ActionResult _LoginPartial(string returnUrl)
{
ViewBag.ReturnUrl = returnUrl;
return PartialView(new LoginModel());
}
[HttpPost]
[AllowAnonymous]
[ValidateAntiForgeryToken]
public ActionResult _LoginPartial(LoginModel model, string returnUrl)
{
if (ModelState.IsValid && WebSecurity.Login(model.UserName, model.Password, persistCookie: model.RememberMe))
{
return RedirectToLocal(returnUrl);
}
// If we got this far, something failed, redisplay form
ModelState.AddModelError("", "The user name or password provided is incorrect.");
return PartialView(model);
}
呈现部分的父页面部分
@{
if(!WebSecurity.IsAuthenticated){
<h2>Use a Creative Works account to log in.</h2>
@Html.Action("_LoginPartial", new {returnUrl = ViewBag.ReturnUrl })
}
}
局部视图
@using (Ajax.BeginForm("_LoginPartial", new {returnUrl = ViewBag.ReturnUrl},
new AjaxOptions(){UpdateTargetId = "loginForm",
InsertionMode = InsertionMode.Replace
})) {
@Html.AntiForgeryToken()
@Html.ValidationSummary(true)
<fieldset>
<legend>Log in Form</legend>
<ol>
<li>
@Html.LabelFor(m => m.UserName)
@Html.TextBoxFor(m => m.UserName)
@Html.ValidationMessageFor(m => m.UserName)
</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>
}