Search code examples
model-view-controllerasp.net-mvc-5

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.


Solution

  • I still don't know why return View(); and similar doesn't execute but in the end I got it working using Javascript's window.location.reload(), full script below for completeness:

    <script type="text/javascript">
        $(document).ready(function () {
            $('.checkbox').click(function () {
                var url = '@Url.Action("CallProcess", "RenderNodes")';
                var networkname = $(this).data("networkname");
                var processname = $(this).data("processname");
                var filename = $(this).data("filename");
                var start = $(this).is(':checked');
                $.post(url, { NetworkName: networkname, ProcessName: processname, FileName: filename, Start: start },
                    function (data) {
                        $("#CallProcess").html(data);
                    });
                window.location.reload(true);
            })
        });
    </script>