[英]Problem with the DateTime "0001-01-01T00:00:00"
我的約會有問題。 我使用 postman 進行插入,無論我輸入什么,我總是返回“0001-01-01T00:00:00”。
還想將 output 限制在日期范圍內。
我非常感謝任何幫助
謝謝你
Model:
public class BusinessTripDocument
{
public long Id { get; set; }
public string StartLocation { get; set; }
[JsonPropertyName("startDateTime")]
public DateTime StartDate { get; set; }
public string Destination { get; set; }
public DateTime DestinationDate { get; set; }
public string Transportation { get; set; }
public string SuperiorsApproval { get; set; }
// POST: api/Businesstripdocuments
[HttpPost("new/{eId}")]
public async Task<ActionResult<BusinessTripDocument>> PostBusinesstripdocuments(long eId, BusinessTripDocument businesstripdocuments)
{
Employee employee = await _context.Employees.FindAsync(eId);
// businesstripdocuments.Employee = employee;
// _context.Businesstripdocuments.Add(businesstripdocuments);
employee.addDocument(businesstripdocuments);
await _context.SaveChangesAsync();
return CreatedAtAction("GetBusinesstripdocuments", new { id = businesstripdocuments.Id }, businesstripdocuments);
}
僅從您顯示的代碼來看 - 在我看來,您應該只需要為您的 Model 提供DataType
屬性?
//using System.ComponentModel.DataAnnotations;
public class BusinessTripDocument
{
...
[DataType(DataType.Date)]
[JsonPropertyName("startDateTime")]
public DateTime StartDate { get; set; }
...
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.