I'm facing a problem doing post requests via ASP.NET Core Web API. I'm a bit confused of the articles I read/found while Googling.
So here's my scenario:
I'm trying to do a HTTP Post request to an api endpoint with a complex parameter.
[HttpPost]
[Route("api/createstudent")]
public async Task<ActionResult> CreateStudent([FromBody]Student student)
{
// Service logic
}
Model:
public class Student
{
public Guid StudentId { get; set; }
public string StudentName { get; set; }
}
My problem is that every time I make a post request to this endpoint the model value is null if I pass below the object.
{"studentId": null,"studentName": "Sam"}
Whereas If I pass empty Guid as below, I am able to get the model.
{ "studentId": "00000000-0000-0000-0000-000000000000", "studentName": "Sam" }
Is this a bug in ASP.NET Core 2? As I was able to pass null / Empty Guid for StudentId in .NET Framework WEB API.