asp.net - 如果未传递参数,如何避免vb.net中的请求查询字符串异常

标签 asp.net .net vb.net

如果未传递参数变量,则此代码将引发异常“从字符串“”转换为“日期”类型无效”。

这是我的代码。

 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/

相关文章:

c# - 在 asp.net mvc 4 中获取登录用户的 ID

.net - WebAPI 多个 Put/Post 参数

WPF 组合框项目更新

c# - Windows 窗体中的事件顺序 'Form.Load' 、 'Form.Shown' 和 'Form.Activated'

.net - 如何在强类型列表中搜索字符串?

vb.net - 包含 1000 多个项目的列表框卡住 Visual Studio

vb.net - 日期时间到字符串的转换

c# - IEnumerator 给出空异常,但不为空

jquery - 将鼠标悬停在 ASP .NET 菜单上

asp.net - .NET 4.5 WebForms : do I (still) really have to specify all 3 templates in a FormView?