Please be gentle with me. Im not an expert.
Im posting a valid json (validated)
{
"Stats": [{
"userName": "sadf",
"id": "128",
"score": "7"
}, {
"userName": "fa",
"id": "417",
"score": "3"
}]
}
// POST api/comment
public void Post(List<Stat> Stats)
{
string break= "Breakpoint here";
}
public class Stat
{
public string userName { get; set; }
public string id { get; set; }
public string score { get; set; }
}
No matter what, then I only get Stats == null in Post(List Stats)
This is the javascript code:
var stats = [{ "userName": "sadf" },
{ "userName": "fa" }];
$.ajax({
type: "POST",
url: "http://localhost:56887/api/comment",
data: JSON.stringify({ Stats: stats }),
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (data) {
$.each(stats, function (k, v) {
alert(v.position);
});
},
failure: function (errMsg) {
alert(errMsg);
}
});
Any idea what's wrong?