Datetime 在API中传递日期
我正在处理.NETCore,希望在api中发布包含日期的属性,但我无法处理api的日期。如何克服这个错误Datetime 在API中传递日期,datetime,postman,asp.net-core-2.0,Datetime,Postman,Asp.net Core 2.0,我正在处理.NETCore,希望在api中发布包含日期的属性,但我无法处理api的日期。如何克服这个错误 使用系统; 使用System.Collections.Generic; 名称空间服务器.Dtos { 公共类项目sessionto { 公共int Id{get;set;} 公共字符串活动{get;set;} 公共字符串ResourcePerson{get;set;} 公共日期时间?TentiveDate{get;set;} 公共日期时间提交日期{get;set;} 公共int-Semes
使用系统;
使用System.Collections.Generic;
名称空间服务器.Dtos
{
公共类项目sessionto
{
公共int Id{get;set;}
公共字符串活动{get;set;}
公共字符串ResourcePerson{get;set;}
公共日期时间?TentiveDate{get;set;}
公共日期时间提交日期{get;set;}
公共int-SemesterId{get;set;}
公共字符串程序{get;set;}
公共字符串批处理{get;set;}
}
}
您需要解决两个问题:
"tentativeDate": "12/12/2019",
"SubmissionDate":"12/12/2019"
[FromBody]
使asp.net核心模型绑定wokring从请求主体读取值:
public async Task<IActionResult> AddProjectSession([FromBody]ProjectSessionDto projectsession)
公共异步任务AddProjectSession([FromBody]ProjectSessionTo projectsession)
旁白:由于这是一个API,我强烈建议您以
yyy-MM-dd
格式传递日期。API中不应使用特定于语言环境的格式。例如,根据所处的地区,人们很容易将日期(如1/2/2020
)混淆在1月2日和2月1日之间。将其作为2020-02-01
传递可以清楚地表明它是2月1日。另见