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");
}
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.
When you call RedirectToAction within a controller, it automatically redirects using an HTTP GET.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With