I just scaffolded my database classes into controllers and added the options to my view but when I try to click them on my navigation bar the action"Index" should be shown but I am receiving this error instead:
Unable to resolve service for type 'Schutters.Models.SchuttersContext' while attempting to activate 'Schutters.Controllers.ClubController'
My startup class:
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public IConfiguration Configuration { get; }
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.AddDbContext<ApplicationDbContext>(options =>
options.UseSqlServer(
Configuration.GetConnectionString("SchuttersConnection")));
services.AddDefaultIdentity<IdentityUser>(options => options.SignIn.RequireConfirmedAccount = true)
.AddEntityFrameworkStores<ApplicationDbContext>();
services.AddControllersWithViews();
services.AddRazorPages();
}
}
The controller that gets called when I click "Clubs" on the navigation bar
public class ClubController : Controller
{
private readonly SchuttersContext _context;
public ClubController(SchuttersContext context)
{
_context = context;
}
// GET: Club
public async Task<IActionResult> Index()
{...}
}
SchuttersContext
. Is it your database context class or what? – Muhammad Vakili