我正在同一页面上处理登录和注册。当我单击注册按钮时,我在不同的控制器中处理,但我不想使用我的 URL。
示例:当我请求时
http:localhost:1853/Account/RegisterLogin
如果模型无效,我想在发布时我的 URL 仍然没有改变。
// GET: /Account/RegisterLogin
[AllowAnonymous]
public ActionResult RegisterLogin(string returnUrl)
{
ViewBag.ReturnUrl = returnUrl;
ViewData["RegisterModel"] = new RegisterModel();
ViewData["LoginModel"] = new LoginModel();
return View();
}
//
// POST: /Account/Register
[HttpPost]
[AllowAnonymous]
[ValidateAntiForgeryToken]
public ActionResult Register(RegisterModel model)
{
if (ModelState.IsValid)
{
// Attempt to register the user
try
{
WebSecurity.CreateUserAndAccount(model.UserName, model.Password, new { Gender = model.Gender, FirstName = model.FirstName, LastName = model.LastName, BirthDate = model.BirthDate, Email = model.Email }, false);
WebSecurity.Login(model.UserName, model.Password);
return RedirectToAction("Index", "Home");
}
catch (MembershipCreateUserException e)
{
ModelState.AddModelError("", ErrorCodeToString(e.StatusCode));
}
}
// If we got this far, something failed, redisplay form
ViewData["RegisterModel"] = model;
ViewData["LoginModel"] = new LoginModel();
return View("RegisterLogin");
}
谢谢你的帮助!