In my web api controller, I am trying to post two parameters: a flat int ID and an IDictionary (or similar equivalent).
[HttpPost]
public void DoStuff(int id, [FromBody]IDictionary<int, int> things)
{
}
var things = new Array();
things.push({ 1: 10 });
things.push({ 2: 11 });
$.ajax({
url: '/api/DoStuff?id=' + id,
data: '=' + JSON.stringify(things),
type: 'POST',
dataType: 'json'
});
Despite multiple attempts with different ways of passing the data parameter (data: things
, data: '=' + things
), the Dictionary doesn't get passed correctly to the api controller. It shows up as null or with incorrect values ({0, 0}).
I also attempted to send the Dictionary in the Uri but was unsuccessful.
Any suggestions on how I can successfully pass the dictionary or key value pair to the api controller?