I am trying to make usage of the IActionResult interface to throw specific exceptions. But at this moment I am stuck at the controller. I've written the following code to get a single call:
[Route("singlecall")]
[HttpGet]
[ProducesResponseType(200, Type = typeof(Models.CallModel))]
[ProducesResponseType(404)]
public async Task<IActionResult> GetSingleCall([FromQuery]string callId, [FromQuery] string token)
{
CallModel singleCall = await CustomerPortalBC.CallManagementBusiness.CallService.GetSingleCall(new Guid(callId), new Guid(token));
if (singleCall == null){
return NotFound();
}
return singleCall;
}
This will (obviously) not work, because I cannot just return the singleCall object. It expects a Microsoft.AspNetCore.Mvc.IActionResult. So I exactly know what the problem is, I only do not know how to solve it.
Any insight or help would be appreciated!
You want to return Ok(singleCall);
Please try:
return Ok(singleCall);
Your object will be then proper HTTP result.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With