MVC3重定向从ActionResult路由

Kas*_*kov 10 c# actionresult asp.net-mvc-3 url-redirection

所以我有一个HttpPostActionResultEdit.在完成它的事情(逻辑等)后,我希望它重定向到另一个控制器.让我们说吧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);

}
Run Code Online (Sandbox Code Playgroud)

伊夫tryed其他像 return RedirectResult(),RedirectToAction(),RedirectToRoute("string")-但它仍保持在返回来自控制器的索引视图中的Edit方法是在(ChairController).

什么是正确的方法?

Dar*_*rov 21

错字:

contoller = "Home"
Run Code Online (Sandbox Code Playgroud)

应该

controller = "Home"
Run Code Online (Sandbox Code Playgroud)

要么:

return RedirectToAction("index", "home");
Run Code Online (Sandbox Code Playgroud)


Kas*_*kov 5

哇最奇怪的事情是造成这种情况.代码是正确的(我确定开始).我试图再次调试它,并注意到我通过代码,调试器thingo只标记了一些代码:return RedirectToAction("Index",它实际上停在那里,并没有通过"Home");.我还注意到我的断点实际上是黄色的,并且告诉我一些关于源代码与原始代码不一致的事情?什么什么?它一直在说通过数百次保存,重启,构建和重建.突然之间它接受了代码,我的断点变成了红色,代码运行得很好.

真的很抱歉等你的时间!