IhttpActionResult的ASP.NET Core Web Api错误

编程入门 行业动态 更新时间:2024-10-23 21:36:07
本文介绍了IhttpActionResult的ASP.NET Core Web Api错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在尝试首次创建一个新的Core Web API应用.我正在使用Core 2.2

I am trying to create a new Core Web API app for the first time. I am using Core 2.2

我做了一些研究,但没有找到正确的答案.不知道我是否使用了错误的库.

I did some research but did not find the correct answer. Not sure if I am using wrong libraries.

不能将microsoft.aspnetcore.mvc.okresult类型隐式转换为system.web.http.Ihttpactionresult

cannot implicitly convert type microsoft.aspnetcore.mvc.okresult to system.web.http.Ihttpactionresult

这是我的代码

using System.Threading.Tasks; using System.Web.Http; using Microsoft.AspNetCore.Mvc; [Microsoft.AspNetCore.Mvc.Route("api/User")] [ApiController] public class UserController : ControllerBase { [Microsoft.AspNetCore.Mvc.HttpGet] public async Task<IHttpActionResult> GetAllUsers() { var users = await this.GetUserAsync(); return this.Ok(users); } }

推荐答案

您需要使用 IActionResult ,而不是 IHttpActionResult .

Core中不存在 IHttpActionResult 接口,它在较旧的Web API项目中使用.

The IHttpActionResult interface does not exist in Core, it's used in older Web API projects.

更多推荐

IhttpActionResult的ASP.NET Core Web Api错误

本文发布于:2023-11-16 09:38:22,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1603111.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:错误   NET   ASP   IhttpActionResult   Api

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!