RedirectToAction not refreshing the page as expected

Michael Low picture Michael Low · Dec 17, 2011 · Viewed 13.4k times · Source

What am I doing wrong with my MVC code here ? The Index view includes a form that submits to itself, what I'd like is the controller to process the submitted form and then return to the View.

What actually happens is the form is processed correctly, but the View returned is as if nothing happen (e.g. ids that have been deleted are still shown). If I manually refresh the page though, it displays correctly again. I don't think it's broswer caching related, as redirecting to the same view from a different controller works fine. How can I fix it ?

    public ViewResult Index()
    {
        return View(GetComments());
    }


    [HttpPost]
    public ActionResult Index(int[] AllIds)
    {
        if (AllIds != null)
        {
            foreach (int id in AllIds)
            {
               // do stuff
            }
        }

        return RedirectToAction("Index");
    }

Edit: When submitting the form, the breakpoint on the first method is not hit and trying to "Step Into (F11)" the return RedirectToAction("Index"); line just moves straight onto the final } instead.

Answer

rick schott picture rick schott · Dec 17, 2011

Install Fiddler or Firebug for Firefox and watch the traffic, see it it really returns a new response or a HTTP 304 from the browser(cached page). If everything checks out then you have a problem with your db persistence and or queries.