Невозможно передать объект json в web api
Когда я запрашиваю у почтальона строку json он работает нормально
Ex -когда я передаю siple 1, он работает, но когда я посылаю это как {"id":"1"}, я не получаю результата
Что я уже пробовал:
namespace DemoApi.Controllers { public class EmployeeController : ApiController { IList employees = new List() { new Employee() { EmployeeId = 1, EmployeeName = "Mukesh Kumar", Address = "New Delhi", Department = "IT" }, new Employee() { EmployeeId = 2, EmployeeName = "Banky Chamber", Address = "London", Department = "HR" }, new Employee() { EmployeeId = 3, EmployeeName = "Rahul Rathor", Address = "Laxmi Nagar", Department = "IT" }, new Employee() { EmployeeId = 4, EmployeeName = "YaduVeer Singh", Address = "Goa", Department = "Sales" }, new Employee() { EmployeeId = 5, EmployeeName = "Manish Sharma", Address = "New Delhi", Department = "HR" }, }; public IList GetAllEmployees() { //Return list of all employees return employees; } [HttpPost] public Employee GetData([FromBody] int id) { var employee = employees.FirstOrDefault(e => e.EmployeeId == id); if (employee == null) { throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.NotFound)); } return employee; } } }
Richard Deeming
Попробуйте удалить его [FromBody]
атрибут на вашем id
параметр.