Reputation: 29365
I have a scenario where I am on a view page and calling a action method in controller A that calls another action in controller B via a RedirectToAction return, and this action returns the view that Im already on.
I want the page to refresh to reflect the updates to the system state these two actions have made, but MVC seems to decide the page does not need to be refreshed as I'm returning to the same view. How do I force a refresh?
Example:
//user is on A/index, and submits a form that calls this in contoller B
public ActionResult ActionInControllerB()
{
//do stuff
return RedirectToAction(ActionNames. ActionInControllerA, ControllerNames.A);
}
public ActionResult ActionInControllerA()
{
//do stuff
return View("index");
}
Upvotes: 12
Views: 11392
Reputation: 487
I had similar problem, but it started from ajax call from the view file to the controller file. The controller made an update to the DB and then call RedirecToAction in order to refresh the view. But no refresh... None of the answers above helped me. The only way I could solve it was by using a different method to call an action from the view file:
window.location = "Experiment/DeleteExperiment?experimentId=" + $("#DeleteExperimentButton").val();
From that point everything acted as I expected to.
Upvotes: 3
Reputation: 18113
I'm guessing you're running into caching problems.
Decorate your ActionInControllerB and ActionInControllerA methods with:
[OutputCache(Location=System.Web.UI.OutputCacheLocation.None)]
Upvotes: 9
Reputation: 2363
I had an issue like this on my project. What might be happening, I am assuming is that you are updating your view in ActionInControllerB then when you RedirectToAction it is clearing that view. I had a problem like this where I was not updating in my GET: controller and was only updating in the POST: controller. Therefore, what I wanted displayed was not coming up. So I would suggest that you just make sure that your changes to the display are happening in the right place.
I am fairly new to MVC so I could just be way misreading your question and if I am, sorry. But, I hope this helps you out at least a bit.
Upvotes: 0
Reputation: 3060
I'm going to be a bit vague here, since I'm not really sure but I've seen something along these lines before (and nobody else is answering). Its possible that the problem is that the update transaction has not yet been processed or flushed before the redirect. For example NHibernate sometimes waits to commit an update to the db until I think after the response is processed.
If this is the case, then whatever fetching you do in controller A is just not picking up the changes. Maybe you could try somehow forcing the database commit to be processed.
Sorry, but thats the only possibility I can think of. You'll have to put on your google-fu outfit and headband!
Upvotes: 0