Avoid Refresh on page generate additional queries to BD MVC C #

0

The case is as follows. My ActionResult does a heavy query in the database and returns random data by business definition.

The user can refresh the screen. If you update the page, you lose what you have done and the return of the query is different.

Does anyone know how to avoid having to re-run or refresh my ActionResult again?

    
asked by anonymous 17.02.2018 / 06:00

1 answer

0

When you do the search for the first time, save in a session or ViewBag, something that says that the search has already been done, then when the user refreshes the page, you check via javascript in the reload event. Example with ViewBag:

ActionResult

ViewBag.Executou = 1;

View

<script type="text/javascript">
    window.onbeforeunload = function() {
        if(@ViewBag.Executou == 1){     
            return false;
        }
    }
</script>

So the page will run only once.

Note: This event does not work in Opera.

    
18.02.2018 / 23:37