Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Return same view does not seem to refresh page

I have controller methods that do stuff with WMI classes (waking selected machine, opening or closing processes, initiating an RDP session) and then reload the current view. To reload I've tried the following:

    return View();
    return RedirectToAction("Index", "RenderNodesController");
    return RedirectToAction("Index");
    return Redirect(Request.UrlReferrer.ToString());

The methods all execute successfully with regards to performing the WMI calls, but the return statement doesn't reload the page. If I refresh the page manually it reloads and displays changed information as expected. Also rather weirdly if I step through the return statements in the debugger I see that the view's Index method executes so debugging seems not to help in this instance. I'd be grateful for any help.

like image 456
codelady Avatar asked Oct 31 '22 04:10

codelady


1 Answers

Just wanted to add some explanation to this answer:

Because you're performing an AJAX request, it won't reload the user's browser page on success, all it will do is return the results of the action method called within the result parameter. $.post is a shorthand version of $.ajax so the behaviour will be the same.

Solution: Use for example location.reload(true) (as you did).

like image 170
maracuja-juice Avatar answered Jan 04 '23 14:01

maracuja-juice