I'm trying to do a POST request of a json object and convert it into a class but it's not working. Here's the JS that's sending the object:
var TheAjaxData = { 'Property1': 'TheValue1', 'Property2': 'TheValue2', 'Property3': 'TheValue3' } $.ajax({ url: "/thewebapi/themethod", type: "POST", data: TheAjaxData, contentType: 'application/json; charset=utf-8', success: function (msg, textStatus, request) { console.log(msg); } }); The WebAPI receives the request so I know the routing is correct but TheObject is null. This is the code:
[RoutePrefix("thewebapi")] public class TheWebAPIController : ApiController { [Route("themethod")] public HttpResponseMessage Post([FromBody] TheRequestObjectModel TheObject) { var testvalue = TheObject.Property1; } public class TheRequestObjectModel { public string Property1 { get; set; } public string Property2 { get; set; } public string Property3 { get; set; } } } This needs to work with a POST, not a GET. I'm pretty sure I'm close but it's not working. What do I need to change to get the object I'm sending converted into TheRequestObjectModel?
data: JSON.stringify(TheAjaxData)