使用存储过程的 Asp.net 核心中的错误数据为空

Error Data is Null in Asp.net core using stored procedure

您好,我正在尝试从我的存储过程中获取数据

这是我的控制器 DashboardController

这是我的 ViewModel DashboardViewModel

这是我的 Javascript AJAXPhoto1 AJAXPhoto2

这是我的 table table

收到 SqlNullValueException 错误:数据为空。此方法或 属性 无法在 Null 值上调用

注意:我的存储过程在从 sql 执行时显示值,而不是在 asp.net 核心

中执行

我对 asp.net 核心还是第一次使用没有 entity framework 的存储过程。任何帮助表示赞赏。谢谢!

你的问题应该是数据库中table中存在一个null value引起的

ViewModel 中的 DateTime 类型不允许空值,默认为 [Required]。但是,由于该属性在您的数据库中可能具有空值,因此您需要将 DateTime 类型更改为可空类型,如下所示。

 public DateTime? DateStarted{ get; set; }
 public DateTime? DateCompleted{ get; set; }
 public DateTime? DueDate{ get; set; }