Posting data to API is null

Viewed 63

When I post a json to the API the body received is always null. I'm using .net core 2.0

[HttpPost]
public  IActionResult UpdateProfile([FromBody] UserProfileView userProfile)
{
    return Ok();
}


public class UserProfileView
{
    [JsonProperty("id")]
    public string Id { get; set; }
    [JsonProperty("email")]
    public string Email { get; set; }
    public string UserName { get; set; }
    public string DisplayName { get; set; }
    public string FirstName { get; set; }
    public string LastName { get; set; }
    public string Gender { get; set; }
    public byte? YearOfBirth { get; set; }
    public List<UserAttribute> Attributes { get; set; }
}

Json I'm posting

{
    "id": "3e9f50c8-358a-4509-bbe4-4f4c6cc00676",
    "email": "joesamraj@outlook.com",
    "userName": "619795228409681",
    "displayName": "Joe Samraj",
    "firstName": "Joe Samraj",
    "lastName": "Muthuraj",
    "gender": "Male",
    "yearOfBirth": "1989",
    "attributes": []
}

Header: Content-Type:application/json

what is wrong here?

1 Answers

I think there is a problem in datatype of your fields. You have yearofbirth field with data type bit and bit will accept values between 0 to 255 so you can change the type of yearofbirth to datetime .

for reference see this byte datatype documentation

Related