所以我有一个 HttpPost
只有 ActionResult
叫做 Edit
。完成它的事情(逻辑等)后,我希望它重定向到另一个 Controller 。比方说 HomeController
。在这里:
[HttpPost]
public ActionResult Edit(Chair chair, string xml)
{
if (ModelState.IsValid)
{
try
{
_repository.EditChair(chair, xml);
return RedirectToRoute(new { contoller = "Home", action = "index"});
}
catch (Exception ex)
{
//error msg for failed edit in XML file
ModelState.AddModelError("", "Error editing record. " + ex.Message);
}
}
return View(Chair);
}
我尝试过其他方法,例如 return RedirectResult()
、RedirectToAction()
、RedirectToRoute("string")
- 但它仍然不断返回Edit
方法位于 (ChairController
) 中的 Controller 的索引 View 。
正确的做法是什么??
最佳答案
错别字:
contoller = "Home"
应该是
controller = "Home"
或:
return RedirectToAction("index", "home");
关于c# - MVC3 重定向到 ActionResult 的路由,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7255378/