I am trying to post an object to the server where I am using Web API 2. The code as follows:
$.ajax({
cache: false,
type: "POST",
url: "/api/Employees",
data: { EmployeeId: 1 },
success: function(result) {
console.log("employees saved successfully");
},
error: function(result) { }
});
As for the Web API:
public class EmployeesController : ApiController
{
// POST api/<controller>
public void Post([FromBody]Employee value)
{
}
}
public class Employee
{
public Int32 EmployeeId { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public string JobTitle { get; set; }
public DateTime BirthDate { get; set; }
public DateTime HireDate { get; set; }
public ReferenceData MaritalStatus { get; set; }
public Int32 VacationDays { get; set; }
public Int32 SickLeaveDays { get; set; }
public decimal Salary { get; set; }
public string Cid { get; set; }
}
I am ending up with this response from server
The requested resource does not support http method 'POST'