I have an API whose return type is ActionResult:
[HttpPost("UploadFiles")]
public async Task<ActionResult> MyFunction(MyFunctionInput input)
{
if (input.Id == null)
{
retrun BadRequest("Id must exist");
}
// Do some stuff
return Ok();
}
I am calling this function from another API in same class and storing the result in a variable. But when ever I am trying to get the StatusCode from the result, it says ActionResult does not contain a definition for StatusCode like this
var response = await MyFunction(attInput);
if (response.StatusCode == System.Net.HttpStatusCode.NotFound ||
response.StatusCode == System.Net.HttpStatusCode.BadRequest)
{
//To Do
}
I googled it but almost everyone said to convert the result to OkObjectResult.
What should I do now?
Generally explain how to get states code in below
If you want request anther api in backend use HttpClient
Make HTTP requests using IHttpClientFactory in ASP.NET Core