Post an array of objects to WebAPI using jQuery
This is quite niche but caught me out the other day.
Let’s say you have a person entity:
and you have a WebAPI method that takes in a group:
You create your call in JavaScript something like this:
You POST that to the API and you get… an empty array. Not great.
jQuery quirk
Turns out this is a known issue and the fix is pretty simple.
Change your data to be a single anonymous object instead of a raw array and it’ll work. So this:
Easy.