Here's my scenario -
I am trying to post a json object with below structure using angular 12 to MVC controller action method.
public class Student{
public string FullName {get;set;}
public int Age {get;set;}
public DateTime BirthDate {get;set;}
}
I have decorated my MVC action method parameter using [FromBody]
attribute.
However, when I try to post the json object to my action, the model just refuses to bind (model object is null)
Next, I tried changing the BirthDate from DateTime => string and observed that model gets bound correctly.
Is there any known issue with model binder OR am I missing any configuration that I need to enable related to datetime ?
My Action
[HttpPost]
public JsonResult Save1([FromBody] Student st)
{
return Json(st);
}
Angular code
this._http.post<any>("../../TupleBinderAPI/Save1", {
fullName: this.FullName,
age: this.Age,
birthDate: this.BirthDate
}, {
headers: {
["Content-Type"]: "application/json; charset=UTF-8"
}
}).subscribe((data: any) => {
console.log(data);
});