如何控制浏览器上按上一页的动作
测试我的应用程序后,我完成了一个具有某些值的表单,保存然后想将另一个人添加到列表中。但当表格进行到一半时,我改变了主意,按下浏览器上的返回按钮,但随后发生了一些奇怪的事情。加载上一个表单中的数据,而不是返回到上一页(应该是人员列表)。
如何防止这种情况发生?
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是纯 JavaScript,因为您可以连接一个名为
onBeforeUnload
的方法,该方法在用户关闭或移动到浏览器中的其他页面时触发。浏览器历史记录。我建议您添加一个类似的脚本(假设您使用的是 jQuery):
Live example。
希望有帮助。
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):
Live example.
Hope it helps.