在我的 ASP.NET Core 应用程序中,出现以下错误:
InvalidOperationException:尝试激活“mvc_net6.Controllers.StudentController”时无法解析类型“mvc_net6.Service.DB_Context”的服务。
StudentController StudentController 是通过 Scaffolds 创建到视图的,如下所示:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Rendering;
using Microsoft.EntityFrameworkCore;
using mvc_net6.Models;
using mvc_net6.Service;
namespace mvc_net6.Controllers
{
public class StudentController : Controller
{
private readonly DB_Context _context;
public StudentController(DB_Context context)
{
_context = context;
}
// GET: Student
public async Task<IActionResult> Index()
{
return View(await _context.Students.ToListAsync());
}
// GET: Student/Details/5
public async Task<IActionResult> Details(int? id)
{
if (id == null)
{
return NotFound();
}
var student …Run Code Online (Sandbox Code Playgroud)