所以我有一个HttpPost
只有ActionResult
叫Edit
。做完它的事情(逻辑等)后,我希望它重定向到不同的控制器。可以说HomeController
。在这里它是:MVC3重定向到ActionResult路由
[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);
}
伊夫tryed其他像return RedirectResult()
,RedirectToAction()
,RedirectToRoute("string")
- 但它仍保持在返回来自控制器的Edit
方法是在(ChairController
)中的索引图。
什么是正确的方法来做到这一点?
这是类似的东西已经... [RedirectToRoute应该如何使用?] [1] 希望它可以帮助... [1]:HTTP://计算器。 com/questions/1290355/how-is-redirecttoroute-supposed-to-be-used –
@Jan谢谢。这似乎是在这个职位上为那个人工作,但不适合我:S FML –
@Kasper猜想我误解了你的问题。我以为你说回到同一个行动 –