skip to Main Content

I have a problem with my date. I do the insert with the postman and no matter what I enter I always get back "0001-01-01T00:00:00".

Would also like to limit the output to just the date.

I am very grateful for any help

thank you

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);
        }

Postman

2

Answers


  1. Just from the code you’ve shown- to me it looks like you should just need to supply the DataType attribute to your Model?

    //using System.ComponentModel.DataAnnotations;
    public class BusinessTripDocument 
    {
        ...
        [DataType(DataType.Date)]
        [JsonPropertyName("startDateTime")]
        public DateTime StartDate { get; set; }
        ...
    }
    
    Login or Signup to reply.
  2. I suggest that you could do two ways:
    1.- The date could be inside the method PostBusinesstripdocuments
    2.- The date could be string in class BusinessTripDocument and after conver to datetime.

    her is the example:
    enter image description here

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search