0

I my backend C Sharp API, I have the below Post controller:

public async Task<ActionResult<bool>> UploadItem(SupplierType supplierType)
{
...
}

SupplierType is an Enum:

public enum SupplierType
{
    Local,
    International,
    Own
}

In my front-end, I call the controller api as below:

  UploadData(supplier: string): Observable<boolean> {
    const httpOptions: { headers: HttpHeaders } = { headers: new HttpHeaders({ 'Content-Type': 'application/json' }) };
    return this.http.post<boolean>(`localhost/UploadItem`, supplier, httpOptions);
  }

The upload data method takes the value from a ng-select component and passes a string with value "0","1","2" as value.

But my controller is not being invoked. Is there a specific way to invoke controllers with enum parameter from angular?

Vida
  • 89
  • 1
  • 8
  • Does this answer your question? [Best practice for passing enum params in Web API](https://stackoverflow.com/questions/39789818/best-practice-for-passing-enum-params-in-web-api) – MoxxiManagarm Nov 24 '22 at 09:43
  • Are you subscribing to UploadData? Request only gets fired upon subscription. – MoxxiManagarm Nov 24 '22 at 09:44
  • which port your api is running. define your port in http.post command like ('localhoost:80/UploadItem') – Barış Can Yılmaz Nov 24 '22 at 09:51
  • @MoxxiManagarm Thanks. It gets triggered after adding the Subscribe. However it is always sending the first value in the enum no matter what I send. – Vida Nov 24 '22 at 09:57

1 Answers1

0

The fix is to add FromBody in the param:

public async Task<ActionResult<bool>> UploadItem([FromBody] SupplierType supplierType)
Vida
  • 89
  • 1
  • 8