[英]MVC3 Redirect to route from ActionResult
所以我只有一個名為Edit
的HttpPost
ActionResult
。 在完成它的事情(邏輯等)后,我希望它重定向到另一個控制器。 讓我們說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
)。
什么是正確的方法?
錯字:
contoller = "Home"
應該
controller = "Home"
要么:
return RedirectToAction("index", "home");
哇最奇怪的事情是造成這種情況。 代碼是正確的(我確定開始)。 我嘗試再次調試它,並注意到我通過代碼,調試器thingo只標記了一些代碼: return RedirectToAction("Index",
它實際上停在那里,並沒有通過"Home");
。 我還注意到我的斷點實際上是黃色的,並且告訴我一些關於源代碼與原始代碼不一致的事情? 什么什么? 它一直在說通過數百次保存,重啟,構建和重建。 突然之間它接受了代碼,我的斷點變成了紅色,代碼運行得很好。
真的很抱歉等你的時間!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.