如果未传递参数变量,则此代码将引发异常“从字符串“”转换为“日期”类型无效”。
这是我的代码。
Public Shared ReadOnly Property Request_projectStartDate() As Date
Get
Dim _value As String = Nothing
If Not HttpContext.Current.Request.QueryString("projectStartDate") Is Nothing Then
_value = HttpContext.Current.Request.QueryString("projectStartDate").ToString()
End If
Return CDate(_value)
End Get
End Property
最佳答案
您可以检查@Massimiliano报告了什么,并再检查一次
If Request.QueryString.HasKeys() Then
// Check for specified querystrings...
If Not String.IsNullOrEmpty(Request.QueryString("projectStartDate")) Then
// Your logic
End If
End If
关于asp.net - 如果未传递参数,如何避免vb.net中的请求查询字符串异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10411524/