0
votes

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()
    {...}
}

enter image description here

1
It seems that you didn't register the SchuttersContext. Is it your database context class or what?Muhammad Vakili
I fixed the problem. I had 2 connections 1 to a security database and 1 to my classes database. I had to add them both to the startup.cs class instead of 1Neal Wicke

1 Answers

0
votes

Fix I had 2 connections and had to put them both in the startup.cs class 1