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
});Written by Abdrashitov Vadim
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Javascript
Authors
Did you know?
JavaScript on a page runs with the privileges of that origin. One altered library, tag manager, or snippet can read inputs, change what people see, and call your APIs as the user.
Security insights from Cside
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#