When I'm sending a POST request to ODataController, record is inserted in the table, but I get the following error "The remote server returned an error: (406) Not Acceptable." GET call for the same controller works just fine.
The URL Im trying to hit is http://localhost:24419/User and JSON body for POST. I'm posting the following JSON (renamed properties):
{
"User_ID":0,
"User_Name":"email@domain.com",
"First_Name":null,
"Middle_Name":null,
"Last_Name":null,
"Telephone_Number":null,
"Alternate_Email":null,
"Record_Update_UTC_Datetime":"2019-08-06T19:42:59.5380526Z",
"Record_Update_Application_User_Name":"username",
}
for the below model
public class User
{
[Key]
public int User_ID { get; set; }
[Required]
[StringLength(255)]
public string User_Name { get; set; }
[StringLength(32)]
public string First_Name { get; set; }
[StringLength(32)]
public string Middle_Name { get; set; }
[StringLength(64)]
public string Last_Name { get; set; }
[StringLength(64)]
public string Telephone_Number { get; set; }
[StringLength(255)]
public string Alternate_Email { get; set; }
[Required]
public DateTime Record_Update_UTC_Datetime { get; set; }
[Required]
[StringLength(128)]
public string Record_Update_Application_User_Name { get; set; }
}
Below is the controller:
public class UserController : ODataController
{
[HttpGet]
[EnableQuery(MaxExpansionDepth = 10, PageSize = 50, MaxNodeCount = 50)]
public async Task<IHttpActionResult> GetUser()
{
var results = await _userService.GetUsers();
return results.MakeWebApiActionResult(this);
}
public async Task<IHttpActionResult> Post([FromBody] User user)
{
var results = await _userService.AddUser(user);
return Ok(results);
}
}
I expect a 200 OK response, but the actual output is :
"ExceptionMessage": "The remote server returned an error: (406) Not Acceptable."