C# IHttpActionResult方法无法返回NotFound()

C# IHttpActionResult方法无法返回NotFound(),c#,asp.net-mvc,asp.net-web-api,C#,Asp.net Mvc,Asp.net Web Api,我正在为我的网站开发一个web API,遇到了一个问题 目前,API应该返回指定用户的详细信息 这是我的帐户控制器: using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; using System.Web.Http; using System.Net; using RoditRepoAPIV2.Models; namespace Rod

我正在为我的网站开发一个web API,遇到了一个问题

目前,API应该返回指定用户的详细信息

这是我的帐户控制器:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Http;
using System.Net;
using RoditRepoAPIV2.Models;

namespace RoditRepoAPIV2.Controllers
{
    public class AccountController : Controller
    {
        Account[] products = new Account[] 
        { 
            //accounts will be added...
        };

        public IEnumerable<Account> GetAllAccounts()
        {
            return products;
        }

        public IHttpActionResult GetAccount(int id)
        {
            var account = products.FirstOrDefault((p) => p.Id == id);
            if (account == null)
            {
                return NotFound();
            }
            return Ok(account);
        }

    }
}
使用系统;
使用System.Collections.Generic;
使用System.Linq;
使用System.Web;
使用System.Web.Mvc;
使用System.Web.Http;
Net系统;
使用RoditRepoAPIV2.模型;
命名空间RoditRepoAPIV2.Controllers
{
公共类AccountController:控制器
{
账户[]产品=新账户[]
{ 
//帐户将被添加。。。
};
public IEnumerable,Visual Studio抱怨当前上下文中不存在“
NotFound()
”和“
Ok(account)
”。我已将所有的NuGet软件包更新到5.1.2+版本,但仍然出现此错误

我做了一些研究,发现它似乎对其他人有用

如果有人能给出有效的解决方案,我将不胜感激!
谢谢。

您需要从
ApiConroller
继承控制器-这就是定义这些方法的地方:

public class AccountController : ApiController