我有一个 web api 控制器,我想向其发布两个参数。一个是 flat int ID,另一个是 IDictionary 或类似的等效项。
[HttpPost]
public void DoStuff(int id, [FromBody]IDictionary<int, int> things)
{
}
var things = new Array();
things.push({ 1: 10 }); // tried things.push({ Key: 1, Value: 10 })
things.push({ 2: 11 });
$.ajax({
url: '/api/DoStuff?id=' + id,
data: '=' + JSON.stringify(things), // tried what seems like 100 different things here
type: 'POST',
dataType: 'json'
});
无论我在数据参数 ( data: things
, data: '=' + things
) 中尝试什么,字典都不会通过 api 控制器。它要么为空,要么有一个虚假条目 ({0, 0})。
我还尝试在 Uri 中发送字典 - 不行。
如何将字典或键值对发送到 api 控制器?