[フレーム]
Last Updated: February 25, 2016
·
594
· jincod

Posting json object which will bind IDictionary<>

HomeController.cs:

public class Notification
{
 public string Name { get; set; }
 public IDictionary<string, string> Fields { get; set; }
}

[HttpPost]
public ActionResult Send(string id, Notification viewModel)
{
 string name = viewModel.Name;
 IDictionary<string, string> fields = viewModel.Fields;
 return Json("Success");
}

post.js:

$.ajax({
 type: 'POST',
 url: "/home/send",
 data: JSON.stringify({
 id: "id1",
 "Name": "name1",
 "Fields": [{
 "Key": "key1",
 "Value": "value1"
 }, {
 "Key": "key2",
 "Value": "value3"
 }]
 }),
 contentType: "application/json",
 dataType: "json",
 processData: false
});

AltStyle によって変換されたページ (->オリジナル) /