I would like to send data (originally arrays) as JSONs to my MVC-controller in the backend. I was trying this:
my-ng-service.ts
//... setEmployees(employees) { var employeesJSON = JSON.stringify(employees); console.log(employeesJSON); //working this.http.post('/api/employees', employeesJSON).subscribe(); } //...
EmployeesController.cs
//... [Route("api/[controller]")] [HttpPost] public void Post(JsonResult data) { Console.Write("hallo: " + data); //error see below } //...
I don't know how I have to write my controller. Can anybody help me?
Current error:
System.Argument.Exception: Type 'Microsoft-AspNetCore.Mvc:JsonResult' does not have a default constructor Parameter name: type
Thanks in forward!
public JsonResult Post(string data)
? Never useJsonResult
as action method argument because it used to return JSON data.