I have api method as below
Scenario 1:
[HttpPost]
[Route("CreateRepo/{name}/{location}/{area}/{zone}")]
public virtual async Task<ActionResult> CreateRepo( string name, string location, string area, string zone)
{
}
and calling above api code from angular as below
public createRepo(name: any, location: any,
area: string, zone: string ): Observable<any> {
let header = { headers: new HttpHeaders(
{ 'Access-Control-Allow-Origin': '*' ,
'Access-Control-Allow-Methods': '*' ,
'Access-Control-Allow-Headers': '*' }
) };
let params = encodeURIComponent(name)+'/'+encodeURIComponent(location)+'/'+encodeURIComponent(area)+'/'+encodeURIComponent(zone);
let url = this.baseUrl+"/CreateRepo/"+params;
return this.httpClient.post<any>(url,header );
}
Using the above code in both API & angular, I'm able to pass values from UI to API.
Scenario 2:
But now my requirement is I want to change route of API as below.
[HttpPost]
[Route("CreateRepo")]
public virtual async Task<ActionResult> CreateRepo( string name, string location, string area, string zone)
{
}
having just method name as Route. I'm not getting how can I pass angular UI values to this api method.
I tried specifying [FromBody] to params of api method , but didn't worked. From UI, api method always getting null values.
Angular UI code:
public createRepo(name: any, location: any,
area: string, zone: string ): Observable<any> {
let header = { headers: new HttpHeaders(
{ 'Access-Control-Allow-Origin': '*' ,
'Access-Control-Allow-Methods': '*' ,
'Access-Control-Allow-Headers': '*' }
) };
let params = { name : name, location:location, area:area, zone:zone}
let url = this.baseUrl+"/CreateRepo/";
return this.httpClient.post<any>(url, params, header );
}
How to fix this?