You could find this problem solved in the source code of my next article:
MVC Basic Site: Step 4 – jqGrid Integration in MVC 4.0 using AJAX, JSON, jQuery, LINQ, and Serialization[
^]
You should look on the next parts:
1. In
AccountController
the method
OnWindowClosing()
that is invoked from
onBeforeUnload
and
onKeyDown
window events, and used to do user session finalization tasks when the browser window is closing.
2.In the main layout view
_Layout.cshtml
the javscript section from the bottom of the file:
function onWindowClosing() {
if (window.event.clientX < 0 || window.event.clientY < 0) {
$.ajax({
type: "POST",
url: "/Account/OnWindowClosing"
});
}
};
function onKeydown(evt) {
if (evt != undefined && evt.altKey && evt.keyCode == 115)
{
$.ajax({
type: "POST",
url: "/Account/OnWindowClosing"
});
}
};
window.onbeforeunload = onWindowClosing;
window.document.onkeydown = onKeydown;