I have an ASP.NET Core 3.1 project with this controller action method:
[HttpGet("{param1:long}", Name = "GetData")]
[ProducesResponseType(StatusCodes.Status200OK)]
public async Task<ActionResult<IReadOnlyList<TestModel>>> GetDataDetails(long param1) => await _testService.GetDetailsAsync(param1);
I'm getting the following error:
Error CS0029
Cannot implicitly convert type 'System.Collections.Generic.IReadOnlyList' to 'Microsoft.AspNetCore.Mvc.ActionResult<System.Collections.Generic.IReadOnlyList>'
Can anyone help me here by providing some guidance?
CodePudding user response:
Your return value expects an ActionResult. Either use Task<IReadOnlyList<TestModel>>
as the result of the function or try to use one of the provided methods that Wrap your result in an ActionResults like this.Ok(await _testService.GetDetailsAsync(param1))