English 中文(简体)
如何在环形核心组群中选取主题图象,以图格尔纽顿为主?
原标题:How to toggle theme color in c# aspnet core with toggle button inside partalview?

<>解释>

我想从小盘中逐个逐个逐个逐个逐个逐个逐个逐个逐个。

洞穴是根据我的具体需求定制的,其价值在需要时可以调取。

部分意见将列入Navbar菜单。

由于某些奇怪的原因,无法找到适当的解决办法,就本案而言。

<<><><><><>>>>><><><>>>>>

如何执行,这是正确的方法?

www.un.org/spanish/ecosoc 部分意见代码

@{

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");
    iii
    else
    {
        HttpContext.Response.Cookies.Delete("mybg");
        HttpContext.Response.Cookies.Append("mybg", "light");
    iii
iii

iii

    <button type="submit" name="submit" class="btn btn-sm btn-outline-light" onclick="ToggleTheme()">

Theme

问题回答

简单明了:

部分观点(在<条码>中的位置/共享/代码>或<条码>上> 意见/共享

@inject Microsoft.AspNetCore.Http.IHttpContextAccessor HttpContextAccessor
@{
    // Read the current theme preference from the cookie
    string currentTheme = HttpContextAccessor.HttpContext.Request?.Cookies["mybg"]?.ToString();
}
<button type="submit" name="submit" class="btn btn-sm btn-outline-light" onclick="ToggleTheme()">ChangeTheme</button>
<script>
    // Function to toggle the theme and save preference in a cookie
    function ToggleTheme() {
        var currentTheme = document.body.classList.contains( theme-dark ) ?  light  :  dark ;

        // Toggle theme class on the body element
        document.body.classList.toggle( theme-dark );

        // Save the theme preference in a cookie
        document.cookie = "mybg=" + currentTheme + "; expires=Fri, 31 Dec 9999 23:59:59 GMT; path=/";
    }

    // Set initial theme based on the cookie
    window.onload = function () {
        var currentTheme = "@currentTheme";
        if (currentTheme === "dark") {
            document.body.classList.add( theme-dark );
        }
    };
</script>
<style>
    .theme-dark {
        background-color: #1f1f1f; /* Dark background color */
        color: #ffffff; /* Light text color on dark background */
        /* Additional styles for dark theme elements */
    }
</style>

Layout

<header>
<nav class="navbar navbar-expand-sm navbar-toggleable-sm navbar-light bg-white border-bottom box-shadow mb-3">
    <div class="container">
        <a class="navbar-brand" asp-area="" asp-page="/Index">IdentityProj8</a>
        <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target=".navbar-collapse" aria-controls="navbarSupportedContent"
                aria-expanded="false" aria-label="Toggle navigation">
            <span class="navbar-toggler-icon"></span>
        </button>
        <div class="navbar-collapse collapse d-sm-inline-flex justify-content-between">
            <ul class="navbar-nav flex-grow-1">
                <li class="nav-item">
                    <a class="nav-link text-dark" asp-area="" asp-page="/Index">Home</a>
                </li>
                <li class="nav-item">
                    <a class="nav-link text-dark" asp-area="" asp-page="/Privacy">Privacy</a>
                </li>
            </ul>
            <partial name="_Partial" />
        </div>
    </div>
</nav>




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签