Explaination
I want to toggle the bootstrap 5.3 theme color through a button inside a partalview.
The toggle button is customised on my specific needs and the value is saved inside a cookie, which i call when needed.
The partial view will be included in the navbar menu.
For some strange reason i can not manage to find a suitable solution, for this case.
Question
How can this be implemented, which is the correct way?
The partialview code
@{
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