这是我的代码:
[HttpPost]
public ActionResult Edit(int id)
{
var viewModel = service.GetUserViewModel(id);
return View(viewModel); // reponse the ValidateLogin view
}
[HttpPost]
public ActionResult EditDetails(UserDetails userDetails)
{
return Edit(userDetails.Id);
}
不幸的是,它没有返回视图,但是却给了我错误。怎么了?
答案 0 :(得分:0)
您无法使用[HttpPost]
从标有return Edit(userDetails.Id)
的其他动作中返回视图,而是必须将一个动作设置为[HttpGet]
(即Edit
动作方法)并使用RedirectToAction()
overload which has route value parameter调用该操作,如下例所示:
[HttpPost]
public ActionResult EditDetails(UserDetails userDetails)
{
// note: the second overload is routeValues
return RedirectToAction("Edit", userDetails.Id);
}
[HttpGet]
public ActionResult Edit(int id)
{
var viewModel = service.GetUserViewModel(id);
return View(viewModel); // reponse the ValidateLogin view
}