I have a class in my api that contains an id and DateTime property.
(我的api中有一个包含id和DateTime属性的类。)
public class MyTestClass
{
public int id { get; set; }
public DateTime dateTime { get; set; }
}
I was wondering if there is a way to accept only a JSON string that has a specific date format.
(我想知道是否有一种方法可以只接受具有特定日期格式的JSON字符串。)
My problem is that the model binder will parse both "21-01-1991" and "01-21-1991". (我的问题是模型联编程序将同时解析“ 21-01-1991”和“ 01-21-1991”。)
sample API controller
(示例API控制器)
public void Post(MyTestClass myTest)
{
DateTime x = myTest.dateTime;
}
I want the api to return bad request in case the user sent the dateTime property in any format other than the iso 8601 format.
(如果用户以iso 8601以外的任何格式发送dateTime属性,我希望api返回错误的请求。)
ask by user2386390 translate from so 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…