I want to be able to display the database name from the dbContext. I have tried to pass it as a ViewBag but when i change page it disappears from the footer.
when I try pass it as a view model the application crashes when i change page.
private readonly DBContext _context;
public HomeController(DBContext context)
{
_context = context;
}
public IActionResult Index()
{
var dbString = _context.Database.GetDbConnection().Database;
return View(new BaseViewModel { DatabaseName = dbString });
}
my BaseViewModel class is just a string property with DatabaseName
then in my footer i have
@using Project.Models.ViewModels;
@model BaseViewModel;
<footer class="app-footer">
<div class="ml-auto">
<span style="font-weight: bold;">
@Model.DatabaseName
</span>
</div>
</footer>
What is the best way to achieve this? I have also have @using Project.Models.ViewModels and @model BaseViewModel in my layout page.