Description
I am looking to change the color scheme of my Bootstrap 5.3 theme by clicking a button within a partial view.
The toggle button is customized to meet my specific requirements, and the chosen value is stored in a cookie for future reference.
This partial view will be integrated into the navigation menu.
Despite extensive efforts, I have not been able to find a suitable solution for this particular scenario.
Query
What is the correct approach to implementing this functionality?
Code snippet from the partial view
@{
static void ToggleTheme()
{
string bg = HttpContext.Request?.Cookies["mybg"]?.ToString();
if (bg == "light" || bg == null)
{
HttpContext.Response.Cookies.Delete("mybg");
HttpContext.Response.Cookies.Append("mybg", "dark");
}
else
{
HttpContext.Response.Cookies.Delete("mybg");
HttpContext.Response.Cookies.Append("mybg", "light");
}
}
}
<button type="submit" name="submit" class="btn btn-sm btn-outline-light" onclick="ToggleTheme()">
Theme