RedirectToAction无法正常工作

时间:2010-07-04 00:10:02

标签: c# asp.net-mvc-2

我有一个简单的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而不是两个指定的动作之一。

1 个答案:

答案 0 :(得分:1)

由于QuickAddEvent正在返回PartialView,因此表单操作将发送到/ EventCalendar / Index而不是/ EventCalendar / QuickAddEvent。该修复程序正在将[httpPost]的操作名称更改为索引

相关问题