I have a Web API controller that accepts an Inspection model, i.e.
public class Inspection
{
public int ID {get; set;}
}
and I have create a POST method on the controller. This works fine and I have tested it with jQuery.
In my javascript page I create an Inspection, i.e.
var inspection = {
ID: '123456'
};
and then do $.ajax like this:
var p = $.ajax({
type: 'POST',
url: 'http://...',
cache: false,
data: JSON.stringify(item),
dataType: 'json',
success: function(response) {
//do stuff
}
});
So my question is: if I have multiple inspections to post, how do I send them all to the controller either in one batch or in single batches?
POST’ing multiple integers in a single call should be easy to do. A few quick things to check:
In your controller, does your method signature look something like:
Note the use of the [FromBody] attribute.
In your POST, is the content type header set to “Content-Type: application/json“?