重定向到浏览器后退按钮上的特定操作,请单击MVC. [英] Redirecting to a specific action on browser back button click MVC
问题描述
当单击浏览器的后退按钮时,如何重定向到控制器操作. 我可以通过单击我自己的按钮或页面上的链接来实现此目的,而无干扰,但是单击浏览器的后退"或刷新"按钮会得到相同的结果.
How can I redirect to a controller action when the browser's back button is clicked. I can achieve this by clicking my own button or link on the page hustle-free but getting the same result from clicking the browser's back or refresh button is an issue.
我有一个名为通知"的控制器
控制器中的一个名为"Unlock" whick的动作将"id"作为参数.
I have a controller called "Notifications"
An action in the contoller called "Unlock" whick takes "id" as an argument.
我的链接可以正常工作:
My Link works perfectly fine:
@Html.ActionLink("Back to List", "Unlock", new { id = Model.NotificationId })
我尝试使用javascript:
I've tried using javascript:
<script>
window.onbeforeunload = function () {
window.location.replace("/Notifications/Unlock/" + "@Model.NotificationId");
}
</script>
即使window.location.href似乎也不起作用.请帮忙.谢谢:)
even window.location.href doesn't seem to work. Please help. Thanks :)
推荐答案
这对我有用:
<script>
window.onunload = function () {
$.ajax({
url: '/Notifications/Unlock/' + '@Model.NotificationId',
type: 'POST',
datatype: "json",
contentType: "application/json; charset=utf-8"
});
};
</script>
这篇关于重定向到浏览器后退按钮上的特定操作,请单击MVC.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!