2 つのパラメーターを投稿したい Web API コントローラーがあります。1 つはフラットな int ID で、もう 1 つは IDictionary または同等の ID です。
[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 コントローラーに到達しません。null であるか、偽のエントリ ({0, 0}) が 1 つあります。
また、辞書を Uri で送信しようとしました。
辞書またはキーと値のペアを API コントローラーに送信するにはどうすればよいですか?