I have an angular app thats sends an array of objects and a .NET API server.
The problem is that my .NET does receive the data but it cannot bind it to objects correctly.
Angular Frontend App:
data: IAccountBookKeeping[] = [];
onClickSendToAPI(){
const httpOptions = {
headers: new HttpHeaders({'Content-Type': 'application/json'})
}
const stringify = fastJson({
type: 'object',
properties: {
AccountingDate: {
type: 'string'
},
RegistrationNo: {
type: 'string'
},
Currency: {
type: 'string'
},
IDKT: {
type: 'string'
},
OriginalIDKT: {
type: 'string'
},
CounterAccountIDKT: {
type: 'string'
},
ProjectCode: {
type: 'string'
},
Balance: {
type: 'string'
},
Text: {
type: 'string'
}
}
})
const jsonString: string[] = [];
this.data.forEach(element => {
jsonString.push(stringify(this.data[0]));
});
this.http.post('http://localhost:5000/api/GFSAccount',
JSON.stringify(jsonString),
httpOptions).subscribe(reponse =>
console.log(reponse));
}
What Angular Frontend send to the API
[" {\"AccountingDate\":\"20171130\",\"RegistrationNo\":\"39A1\",\"Currency\":\"DKK\",\"IDKT\":\"34HS991016\",\"OriginalIDKT\":\"test\",\"CounterAccountIDKT\":\"34HS980876\",\"ProjectCode\":\"078\",\"Balance\":\"1\",\"Text\":\"006-Hest prov-Ytd NOV17\"}","{\"AccountingDate\":\"20171130\",\"RegistrationNo\":\"39A1\",\"Currency\":\"DKK\",\"IDKT\":\"34HS991016\",\"OriginalIDKT\":\"test\",\"CounterAccountIDKT\":\"34HS980876\",\"ProjectCode\":\"078\",\"Balance\":\"1\",\"Text\":\"006-Hest prov-Ytd NOV17\"}"
ASP .NET API Server Receiving
[HttpPost]
public IActionResult Post([FromBody] IEnumerable<AccountBookKeeping> request)
{
return Ok(request);
}
ASP .NET AccountBookKeeping Class
public class AccountBookKeeping
{
public string AccountingDate { get; set; }
public string RegistrationNo { get; set; }
public string IDKT { get; set; }
public string OriginalIDKT { get; set; }
public string CounterAccountIDKT { get; set; }
public string Text { get; set; }
public string ProjectCode { get; set; }
public string Currency { get; set; }
public string Balance { get; set; }
}
this.data? The array you want to post?