因此,我阅读了这种称为 PRG 的方法,作为解决表单重复提交问题的一种方法。但是,我还没有找到向用户显示的摘要页面/成功消息的下降实现。我能想到的唯一方法是存储会话变量,但我不希望它在多次刷新时持续存在。它应该显示一次消息/摘要,然后完成。此外,如果用户不能返回到先前提交的页面,那将是理想的。
这是我的 PRG 代码:
Protected Sub InsertRequest() Handles wizard.FinishButtonClick
Using connection As New SqlConnection(connectionStr)
Dim insertQuery As New SqlCommand("spInsertRequest", connection)
insertQuery.CommandType = CommandType.StoredProcedure
'1 - SETUP SQL PARAMETERS (omitted for brevity)
'2 - POST (inserts record into DB)
Try
connection.Open()
insertQuery.ExecuteNonQuery()
connection.Close()
Catch ex As Exception
Logger.WriteToErrorLog(Me, ex.Source, ex.Message, ex.StackTrace)
End Try
'3 - REDIRECT (to the same page and...)
Try
Dim urlRedirect As String = If(IsNothing(Request.Url), "", IO.Path.GetFileName(Request.Url.AbsolutePath)) 'Gets the filename of the current page.
If Not String.IsNullOrEmpty(urlRedirect) Then
Session.Add("referrerPage", urlRedirect) 'Used for identifying when the page is being redirected back to itself.
PageExt.AddParam(urlRedirect, "id", recID.ToString)
Response.Redirect(urlRedirect)
End If
Catch ex As Exception
Logger.WriteToErrorLog(Me, ex.Source, ex.Message, ex.StackTrace)
End Try
End Sub
'4 - GET (Display 'Success' message/summary here)
问题是,如何在直接由提交产生的重定向上显示此消息,最好不要进一步刷新?或者只是简单地显示消息而不考虑刷新,无论是最简单和最有意义的。谢谢 ;)