I am using ajax to pass Json data to an action in an asp.net core project. I have an array of objects to pass
var AgentScores = [];
.
.
.
AgentScores.push({
AgentId: AgentId,
Fullname: Fullname,
Score : Score
});
$.ajax({
type: "POST",
url: "/Score/SelfReportedScores",
contentType: 'application/json; charset=utf-8',
//large data must be passed using json
data: JSON.stringify(AgentScores),
success: function (result) {
},
error: function (e) {
}
});
I have a class called AgentsListScoreClass.cs and below is how I am trying to get the array in my action:
public void SelfReportedScores([FromBody] List<AgentsListScoreClass> AgentScores)
{
AgentScores
is always null.
It is ok when I pass a List of string, but with AgentsListScoreClass
it is always null.
public class AgentsListScoreClass
{
public string AgentId { get; set; }
public string Fullname { get; set; }
public short Score { get; set; }
}