0
我有一個簡單的MVC2應用程序,似乎沒有正確重定向。該代碼的設置如下:RedirectToAction無法正常工作
[HttpPost]
[Authorize]
public ActionResult QuickAddEvent(CalendarEvent calEvent)
{
if (ModelState.IsValid)
{
int eventID = repo.AddEvent(calEvent);
return RedirectToAction("Event", new { id = eventID });
}
return RedirectToAction("Index", "Home");
}
[ChildActionOnly]
public ActionResult QuickAddEvent()
{
return PartialView();
}
public ActionResult Event(int id)
{
CalendarEvent curEvent = repo.ByID(id);
return View(curEvent);
}
我遇到的問題是,無論是ModelState中對什麼的HttpPost頁面重定向到本身。也就是說,無論模型狀態如何,我總是以/ EventCalendar/Index結尾,而不是指定的兩個操作之一。
這是您的答案嗎?如果沒有,你應該編輯這個到你的文章 – msarchet 2010-07-04 00:29:05
@msarchet是啊,我回答我自己的問題。 – Scott 2010-07-04 00:41:55