views:

26

answers:

1

I have a simple MVC2 app that doesn't seem to Redirect correctly. The code is setup as follows:

    [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);
    }

The problem I am running into is that no matter what the ModelState is on HttpPost the page redirects to itself. That is, no matter what the model state is, I always end up at /EventCalendar/Index instead of one of the two specified actions.

+1  A: 

Since QuickAddEvent is returning a PartialView, the form action isposting to /EventCalendar/Index and not /EventCalendar/QuickAddEvent. The fix is changing the action name for the [httpPost] to index

Scott
@scott is this your answer? If not you should probably edit this into your post
msarchet
@msarchet yeah, I'm answering my own question.
Scott