I am trying to send an object to a server where I am using Web API 2. The code is as follows:
$.ajax({ cache: false, type: "POST", url: "/api/Employees", data: { EmployeeId: 1 }, success: function(result) { console.log("employees saved successfully"); }, error: function(result) { } });
Regarding 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 get this response from the server
The requested resource does not support http method 'POST'
source share