Why is ASP.NET Core sending empty objects in responses?

Issue

When I call the endpoint /api/wizard/cities from the code below, I receive a response of 3 list items of empty objects instead of the expected response of two list items with properties as shown. How can I resolve this issue?

Model Class

public class City
{
    public string CityName;
    public string AssociatedCities; 
    public string Province;
    public int Status;

    public City(string cityName, string associatedCities, string province, int status)
    {
        this.CityName = cityName;
        this.AssociatedCities = associatedCities;
        this.Province = province;
        this.Status = status;
    }
}

Endpoint

[HttpGet]
[Route("cities")]
public ActionResult<IEnumerable<City>> GetCities()
{
    return Ok(Cities);
}

Code Calling Endpoint

getCities() {
  this.http.get<City[]>('/api/wizard/cities')
  .subscribe(result => {
    console.log(result);
    this.cities = result;
  }, error => console.error('Something went wrong : ' + error));
}

Expected Response

[
  {
    "SearchCity": "Toronto",
    "AssociatedCities": "Ajax, Whitby, Toronto, Mississauga, Brampton",
    "Province": "ON",
    "Status": 1
  },
  {
    "SearchCity": "Vancouver",
    "AssociatedCities": "Vancouver, Vancouver City",
    "Province": "BC",
    "Status": 1
  }
]

Previous Attempt

I have already tried Fresh ASP.NET Core API returns empty JSON objects.

The issue is caused by the fact that the properties of the City class are declared as fields instead of properties with getters and setters. In order to serialize the object correctly, you need to convert the fields to properties.

Here is the updated City class:

public class City
{
    public string CityName { get; set; }
    public string AssociatedCities { get; set; }
    public string Province { get; set; }
    public int Status { get; set; }

    public City(string cityName, string associatedCities, string province, int status)
    {
        this.CityName = cityName;
        this.AssociatedCities = associatedCities;
        this.Province = province;
        this.Status = status;
    }
}

Make sure to update the City class in your code accordingly. This should resolve the issue and return the expected response.