c# - MVC3 重定向到 ActionResult 的路由

标签 c# asp.net-mvc-3 actionresult url-redirection

所以我有一个 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/

相关文章:

c# - 在剪贴板更改时修改剪贴板内容

c# - Debug.Assert() 有意想不到的副作用 - 寻找替代品

c# BackgroundWorker DoWork 方法调用另一个类和 ProgressReport

asp.net-mvc - Razor 要求;使用时(Html.BeginForm())

asp.net-mvc - 多部分 http 响应的自定义 ActionResult?

c# - 是否有可能使非 ActionResult 方法返回 ActionResult ... 或最佳/最新的解决方法?

asp.net - 在 ASP.Net MVC 中禁用每个请求的 session 状态

c# - 如何保证异步方法继续在另一个线程上运行?

asp.net-mvc - 主流搜索引擎无法抓取 MVC 站点?

asp.net-mvc-3 - 不使用 Razor 的 MVC 3?