I'm getting an array returned from an API call. The array looks something like this https://i.sstatic.net/l7SYW.png.
I get the array, then call my controller method using this
this.http.post<Maps[]>(this.baseUrl + "api/Map/InsertMap/", beatmaps[0]).subscribe();
Maps being an interface
interface Maps {
Id: number;
Name: string;
Artist: string;
Creator: string;
}
Now I just have a basic insert controller method
[Route("api/[controller]/InsertMap/")]
[HttpPost("[action]")]
public async Task<IActionResult> AsyncCreateMap(MapModel model)
{
await _mapService.AsyncInsert(model);
return Ok();
}
It takes in the Model as a parameter and then inserts it using Entity Framework. It doesn't work. I have no idea how to actually transfer the array I get to an object I can use in my controller.
Here is my whole controller class
[Route("api/[controller]")]
public class MapController : Controller
{
private readonly MapService _mapService;
public MapController(MapService mapService)
{
_mapService = mapService;
}
[Route("api/[controller]/Maps")]
[HttpGet("[action]")]
public async Task<IActionResult> AsyncMaps()
{
var data = await _mapService.AsyncGetMaps(0, 10);
return Ok(data);
}
[HttpPost]
public async Task<IActionResult> AsyncCreateMap([FromBody]MapModel model)
{
await _mapService.AsyncInsert(model);
return Ok();
}
}
modelis null? Controller is not hit? Something else?POST https://localhost:44311/api/Map/InsertMap/ 404But it can't be 404 as I have defined it. @Crowcoder[action]onHttpPost? and alsoRoute?POST https://localhost:44311/api/Map/AsyncCreateMap/ 404. I've updated the OP with my controller class.