Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RedirectToAction not refreshing the page

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");
}
like image 518
Dan Avatar asked Aug 21 '09 08:08

Dan


People also ask

What is difference between redirect and RedirectToAction?

RedirectToAction is meant for doing 302 redirects within your application and gives you an easier way to work with your route table. Redirect is meant for doing 302 redirects to everything else, specifically external URLs, but you can still redirect within your application, you just have to construct the URLs yourself.

Is RedirectToAction a post or a get?

When you call RedirectToAction within a controller, it automatically redirects using an HTTP GET.

What is RedirectToAction MVC?

RedirectToAction(String) Redirects to the specified action using the action name. RedirectToAction(String, Object) Redirects to the specified action using the action name and route values.

Can we pass model in RedirectToAction?

Finally, the PersonModel class object is passed to the RedirectToAction method along with the name of the destination Controller and its Action method. The Controller consists of the following Action method. Inside this Action method, the PersonModel class object is received.


1 Answers

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.

like image 130
Asaf Avatar answered Sep 23 '22 15:09

Asaf