网络 API 项目。我创建了一个新控制器,想连接 Web.Http 命名空间,但它说“无法解析 http 符号”,这是什么问题?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using System.Web.Http;
using WebApiJack.Models;
namespace WebApiJack.Controllers
{
public class ProductsController : Controller
{
Product[] products = new Product[]
{
new Product { Id = 1, Name = "Tomato Soup", Category = "Groceries", Price = 1 },
new Product { Id = 2, Name = "Yo-yo", Category = "Toys", Price = 3.75M },
new Product { Id = 3, Name = "Hammer", Category = "Hardware", Price = 16.99M }
};
public IEnumerable<Product> GetAllProducts()
{
return products;
}
public IHttpActionResult GetProduct(int id)
{
var product = products.FirstOrDefault((p) => p.Id == id);
if (product == null)
{
return NotFound();
}
return Ok(product);
}
}
}
PS 已经搜索过答案,但只找到了 VS

通过 Nuget 安装 Microsoft.AspNet.WebApi.Core,System.Web.Http 命名空间将可用。