如何控制浏览器上按上一页的动作

发布于 2024-11-08 04:53:46 字数 1279 浏览 0 评论 0原文

测试我的应用程序后,我完成了一个具有某些值的表单,保存然后想将另一个人添加到列表中。但当表格进行到一半时,我改变了主意,按下浏览器上的返回按钮,但随后发生了一些奇怪的事情。加载上一个表单中的数据,而不是返回到上一页(应该是人员列表)。

如何防止这种情况发生?

  Function AddPersoon(subdienstid As Integer) As ActionResult
        Dim viewModel As New PersoonViewModel
        ViewData("Persoon.rijbewijsId") = ConvertToSelectlistItemList(_iSubDienstService.GetAllRijbewijzen(), 1)
        ViewData("Persoon.PersoonStatusId") = ConvertToSelectlistItemList(_iSubDienstService.GetAllPersoonStatussen(), 1)
        Return View(viewModel)
    End Function

    <HttpPost()> _
    Function AddPersoon(subdienstid As Integer, model As PersoonViewModel) As ActionResult
        If ModelState.IsValid Then
            Try
                _iSubDienstService.AddPersoonTo(subdienstid, model)
                Return RedirectToAction("Details", New With {.id = subdienstid})
            Catch ex As Exception

            End Try
        End If
        ViewData("Persoon.rijbewijsId") = ConvertToSelectlistItemList(_iSubDienstService.GetAllRijbewijzen(), model.Persoon.RijbewijsId)
        ViewData("Persoon.PersoonStatusId") = ConvertToSelectlistItemList(_iSubDienstService.GetAllPersoonStatussen(), model.Persoon.PersoonStatusId)
        Return View(model)
    End Function

After testing my application i completed a form with some value , saved then wanted to add another person to the list. but when halfway the form i changed my mind and i press the return button on the browser but then something weird happens. the data from the previous form gets loaded instead of a return to the previous page(should be a list of persons).

How do you prevent this from happening?

  Function AddPersoon(subdienstid As Integer) As ActionResult
        Dim viewModel As New PersoonViewModel
        ViewData("Persoon.rijbewijsId") = ConvertToSelectlistItemList(_iSubDienstService.GetAllRijbewijzen(), 1)
        ViewData("Persoon.PersoonStatusId") = ConvertToSelectlistItemList(_iSubDienstService.GetAllPersoonStatussen(), 1)
        Return View(viewModel)
    End Function

    <HttpPost()> _
    Function AddPersoon(subdienstid As Integer, model As PersoonViewModel) As ActionResult
        If ModelState.IsValid Then
            Try
                _iSubDienstService.AddPersoonTo(subdienstid, model)
                Return RedirectToAction("Details", New With {.id = subdienstid})
            Catch ex As Exception

            End Try
        End If
        ViewData("Persoon.rijbewijsId") = ConvertToSelectlistItemList(_iSubDienstService.GetAllRijbewijzen(), model.Persoon.RijbewijsId)
        ViewData("Persoon.PersoonStatusId") = ConvertToSelectlistItemList(_iSubDienstService.GetAllPersoonStatussen(), model.Persoon.PersoonStatusId)
        Return View(model)
    End Function

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

九命猫 2024-11-15 04:53:46

如何控制浏览器上按上一页的动作

这是纯 JavaScript,因为您可以连接一个名为 onBeforeUnload 的方法,该方法在用户关闭或移动到浏览器中的其他页面时触发。浏览器历史记录。

我建议您添加一个类似的脚本(假设您使用的是 jQuery):

var msg = "You're about to leave this page, all changes will not been save.\n" +
          "Are you sure you want to leave?";

$(window).bind("beforeunload", function () {
    if( confirm(msg) ) 
        return true;
    return false;
});

Live example

希望有帮助。

How to control the action of pressing the previous page on a browser

This is pure javascript, as there are a method that you can hook up called onBeforeUnload that fires when a user closes or moves to other page in the browser history.

I would recommend that you add a script like (and assuming you're using jQuery):

var msg = "You're about to leave this page, all changes will not been save.\n" +
          "Are you sure you want to leave?";

$(window).bind("beforeunload", function () {
    if( confirm(msg) ) 
        return true;
    return false;
});

Live example.

Hope it helps.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文