问题
I developed an ASP.NET Core 2.0 Web API service and try to use HttpGet
method: http://localhost:50223/api/ArtistsLibrary/ListArtists
[HttpGet]
[Produces("application/json")]
[Route("ListArtists")]
public JsonResult ListArtists()
{
var artists = _context.Artists.ToList();
return Json(new { results = artists });
}
public class Artist
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int id { get; set; }
public FakeData fake { get; set; }
}
public class FakeData
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int id { get; set; }
public string name { get; set; }
}
It returns:
{
"results": [
{
"id": 1,
"fake": {
"id": 1,
"name": "m1"
}
},
{
"id": 2,
"fake": {
"id": 2,
"name": "m2"
}
}
]
}
Everything is OK, but when I try to get the data from Angular 7, I got "fake = null":
getArtistsList(): Observable<Artist[]> {
return this.http.get<Artist[]>(this.myAppUrl +
'api/ArtistsLibrary/ListArtists'); }
LoadData() {
this._artistsService.getArtistsList().subscribe((d) => {
debugger;
this.artists = d;
console.log(this.artists);
});
}
Results:
Array(2) 0: fake: null id: 1
1: fake: null id: 2
Please help me.
来源:https://stackoverflow.com/questions/53962597/dont-see-object-values-from-asp-net-core-mvc-in-angular-7-http-get