我有一个简单的MVC2应用程序,似乎没有正确重定向。代码设置如下:
[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);
}
我遇到的问题是,无论httppost上的modelstate是什么,页面都会重定向到自身。也就是说,无论模型状态是什么,我总是以/eventcalendar/index结束,而不是两个指定操作中的一个。