Created
April 26, 2012 15:50
-
-
Save jincod/2500521 to your computer and use it in GitHub Desktop.
Posting json object which will bind IDictionary<>
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$.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 | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Cool, thanks a lot!
But, what I really wanted to archive is then you able to POST
{
id: 1,
name: "name",
fields: {
"key" : "value"
}
};
since it's native JSON representation of Javascript object.