asp.net C#异步任务< IActionResult>返回对象

j9per5c4  于 5个月前  发布在  .NET
关注(0)|答案(3)|浏览(115)

我尝试使用Icons Result接口来抛出特定的异常。但此时我被控制器卡住了。我编写了以下代码来获取单个调用:

[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;
    }

字符串
这(显然)不起作用,因为我不能只返回singleCall对象。它需要一个Microsoft.AspNetCore.Mvc.IclassResult.So我确切地知道问题是什么,我只是不知道如何解决它。
任何见解或帮助将不胜感激!

6kkfgxo0

6kkfgxo01#

你要return Ok(singleCall);

q1qsirdb

q1qsirdb2#

请尝试:

return Ok(singleCall);

字符串
您的对象将是正确的HTTP结果。

waxmsbnn

waxmsbnn3#

您也可以返回自定义消息。

catch (Exception ex)
{
   return Json(new { status = "error", message = ex.InnerException });
}

字符串

相关问题