我想从同一 Controller 中的 [HttpGet]
操作重定向到 [HttpPost]
操作。
这可能吗?
我尽量不为登录重写相同的代码,因为它很复杂,而且不是典型的登录功能
这是我的代码:
[HttpGet]
public ActionResult Login(){
return View();
}
[HttpPost]
public ActionResult Login(LoginModel model)
{
//search user and create sesion
//...
if (registered)
{
return this.RedirectToAction("Home","Index");
}else{
return this.RedirectToAction("Home", "signIn");
}
}
[HttpGet]
public ActionResult signIn(){
return View();
}
[HttpGet]
public ActionResult signInUserModel model)
{
//Register new User
//...
if (allOk)
{
LoginModel loginModel = new LoginModel();
loginModel.User = model.User;
loginModel.password = model.password;
//next line doesn't work!!!!!
return this.RedirectToAction("Home","Login", new { model = loginModel);
}else{
//error
//...
}
}
如有任何帮助,我们将不胜感激。
谢谢
最佳答案
可以从方法名返回不同的View
public ActionResult signInUserModel model)
{
...
return View("Login", loginModel);
}
有点晚了,但我遇到了同样的问题......
关于asp.net-mvc - 从 [HttpGet] 操作重定向到 [HttpPost] 操作 - MVC3,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14380648/