I setup a new .net core application but it has no access to my database or _context like the rest of my controllers do. I would like to be able to access my database information on the home screen. Is this possible and if so, how can I pass a context or instantiate a database context on the home controller?
Asked
Active
Viewed 382 times
0
-
Solved by lucking into another post, for anyone looking in the future check this post: https://stackoverflow.com/questions/30925122/mvc-multiple-models-in-one-view – user7704925 May 03 '19 at 22:56
1 Answers
0
you can first of all modify the HomeController constructor to replace the logger with the context as follows:
private readonly ILogger<HomeController> _logger;
private readonly YourDbContext _context;
public HomeController(YourDbContext context)//ILogger<HomeController> logger)
{
//_logger = logger;
_context = context;
}
in your methods you can use _context to access your database.