【发布时间】:2011-11-07 11:53:56
【问题描述】:
所以我有一个 HttpPost 只有 ActionResult 称为 Edit。在完成它的事情(逻辑等)之后,我希望它重定向到另一个控制器。让我们说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) 中。
这样做的正确方法是什么??
【问题讨论】:
-
这里已经有类似的东西了... [RedirectToRoute 应该如何使用?][1] 希望它有所帮助... [1]:stackoverflow.com/questions/1290355/…
-
@Jan 谢谢。它似乎对帖子中的那个人有用,但不适合我:S FML
-
@Kasper 猜我误解了你的问题。我以为你说返回相同的动作
-
@David 和所有其他人。没关系。原来是VS10搞砸了。我见过的最奇怪的事情。查看我的答案以获取更多信息。
标签: c# asp.net-mvc-3 actionresult url-redirection