来自 SQL 的 .NET Web API,错误:CS0029 无法将类型“System.Collections.Generic.List”隐式转换为“Microsoft.AspNetCore.Mvc.ActionResult”

问题描述 投票:0回答:1

我正在尝试从单个 SQL 表创建一个简单的 .NET Web API,但我在控制器开发中遇到了这个问题:

Code for OptOutController.cs and error in bottom

This is the OptOut model

This is program.cs

我还没有尝试过任何东西,因为我对此很陌生。

c# database asp.net-core type-conversion
1个回答
0
投票

您需要返回

ActionResult
:

错误:无法从List转换为ActionResult

函数返回是

Task<ActionResult<IEnumerable<OptOut>>>

将返回结果封装在

Ok()
函数调用中。

© www.soinside.com 2019 - 2024. All rights reserved.