12
我在嘗試使用RedirectToAction時收到此錯誤,任何人都可以提供任何建議,可能會發生,我之前使用這個沒有任何問題,我必須錯過一些東西。RedirectToAction MVC2的問題 - 不能將類型'System.Web.Mvc.RedirectToRouteResult'隱式轉換爲'System.Web.Mvc.ViewResult'
不能鍵入 'System.Web.Mvc.RedirectToRouteResult' 隱式轉換爲 'System.Web.Mvc.ViewResult'
[HttpPost]
public ViewResult Edit(Customer customer)
{
if (ModelState.IsValid)
{
customersRepository.SaveCustomer(customer);
TempData["message"] = customer.CustomerName + " has been saved.";
return RedirectToAction("Index");
}
else //validation error, so redisplay the same view
return View(customer);
}
問候
利亞姆
謝謝你,我認爲這可能是簡單的事情。 – liam 2011-06-03 12:13:10
你知道這是爲什麼嗎? – 2012-05-04 07:35:37
我更新了我的答案。基本上,'ViewResult'只能返回一個'View',而不是'RedirectToAction' – jao 2012-05-04 14:02:53