0

I am using Angular when using datepicker I get this error:

HttpErrorResponse {headers: HttpHeaders, status: 500, statusText: "Internal Server Error", url: "http://localhost:53626/api/Customer", ok: false, …}error: " ↵http://localhost:53626/api/Customer: 500 Internal Server Error"name: "HttpErrorResponse"ok: falsestatus: 500statusText: "Internal Server Error"url: "http://localhost:53626/api/Customer"proto: HttpResponseBase

<input
      name="dob"
      #dateOfBirth="ngModel"
      [(ngModel)]="service.formData.dateOfBirth"
      class="form-control"
      type="text"
      maxlength="10"
      bsDatepicker
    />

When I remove bsDatepicker it works fine in simple HTML. I have tried Material Datepicker as well but the server error persists. Back-end model contains validation maybe the data does not match when sent from a date picker:

 public class Customer
    {
        [Key]
        public int id { get; set; }
        [Required]
        [Column(TypeName ="nvarchar(100)")]
        public string name { get; set; }
        [Column(TypeName = "varchar(10)")]
        public string gender { get; set; }
        [Required]
        [Column(TypeName = "varchar(10)")]//10/10/2019
        public string dateOfBirth { get; set; }


        public Boolean isActive { get; set; }

    }
}
  • Use your browser's dev tools and check the body of the request you are sending. Compare the dateOfBirth values it is sending to your server with and without the `bsDatepicker` attribute. Chances are you need to change the format of `service.formData.dateOfBirth` to `10/10/2019` before you send it to your server when you use the date picker – Noremac Sep 24 '19 at 20:58
  • a error 500 is an error in server. NOTE: You can get a Date in the server as `DateTime` if you send a Date javascript object – Eliseo Sep 25 '19 at 06:44

0 Answers0