我正在閱讀微軟關(guān)于創(chuàng)建 web api 的官方教程。 https://docs.microsoft.com/en-us/aspnet/core/tutorials/first-web-api?view=aspnetcore-2.1現(xiàn)在我正在 Visual Studio 中試用它,并且完全按照教程中的描述進(jìn)行操作。但我收到 2 個錯誤:1)找不到類型或命名空間名稱“ApiController”[CS0246] 2)類型“ActionResult”不是通用的,不能與類型參數(shù)一起使用 [CS0308]教程是否已過時或為什么我會收到這些錯誤?這是控制器:using System;using System.Collections.Generic;using System.Linq;using System.Threading.Tasks;using Microsoft.AspNetCore.Mvc;using TodoApi.Models;namespace TodoApi.Controllers{ [Route("api/[controller]")] [ApiController] public class TodoController : ControllerBase { private TodoContext _context; [HttpGet] public ActionResult<List<TodoItem>> GetAll() { return _context.TodoItems.ToList(); } [HttpGet("{id}", Name = "GetTodo")] public ActionResult<TodoItem> GetById(long id) { var item = _context.TodoItems.Find(id); if (item == null) { return NotFound(); } return item; } public TodoController(TodoContext context) { _context = context; if(_context.TodoItems.Count() == 0) { _context.TodoItems.Add(new TodoItem { Name = "Item1" }); _context.SaveChanges(); } } }}
- 1 回答
- 0 關(guān)注
- 206 瀏覽
添加回答
舉報
0/150
提交
取消