how do i send an array of objects from angular to the web api core in httpget?

How to send array of object from Angular to Web API Core in HttpGet?

If you’d like to pass complex data through a HTTP Get request to your , you can try dynamically generate data and pass it through the query string, like below.

params = "";

GetData() {

  // generate querystring based on PropertiesParams
  this.PropertiesParams.forEach((currentValue, index) => {
    this.params +=
      "_Properties[" +
      index +
      "].Name=" +
      currentValue.Name +
      "&" +
      "_Properties[" +
      index +
      "].Filter=" +
      currentValue.Filter +
      "&";
  });

  this.http
    .get(this.url + "/LSetting/Getsetting?" + this.params.slice(0, -1))
    .subscribe(
      (response: ServiceResponse) => {
        if (response.success && response.data != null) {
        } else console.log(response.message);
      },
      (error: ServiceResponse) => {
        console.log(error.message);
      }
    );

}

Action method

[HttpGet("Getsetting")]
public async Task<ServiceResponse> GetData([FromQuery] List<PropertiesParams> _Properties)
{
    return new ServiceResponse();
}

Test Result

enter image description here

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top