该字符串未被识别为有效的DateTime
报错:该字符串未被识别为有效的DateTime。值为空
前提:
服务端对时间做了一次转换:DateTime.Parse(Request[“时间字段”].ToString())。
搜索的时候没有选择点击datapicker,从而报错,出错的点停在了DateTime.Parse(Request[“时间字段”].ToString())上。
发生异常:
再转换DateTime的时候,发生了错误。当某个实参的格式不符合方法的形参规范时,该方法会引发 FormatException 异常。
解决方法:
在转换前,对时间是否为Null做一个判断,在视图上做一个是否为空的判断
//判断业务日期时间是否为null
if (!string.IsNullOrEmpty(Request["Pusinessdate"]))
{
var time = DateTime.Parse(Request["Pusinessdate"].ToString());
}