IhttpActionResult的ASP.NET Core Web Api错误 [英] ASP.NET Core Web Api Error for IhttpActionResult

查看:51
本文介绍了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错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆