html - Razor-pages - 动态切换 css 背景/主题
问题描述
问题:如何动态更改 div 类/主题。从“nul”到“bg-info”再到“bg-success”
IE:
<div class="container body-content">
<div class="container body-content bg-info">
<div class="container body-content bg-success">
(Razor-pages 2.1.1 / Visual Studio 2017 / EF 2.1.1)(引导程序 - 无控制器结构)
设置:EF/localDB 切换或列出选项。
使用的 VS 模板:C# > .Net Core > .Net Core Web 应用程序 > Razor-pages
解决方案
我的页面.cshtml:
@page
@using MyProject.Pages
@model MyPageModel
<div class="container body-content@Model.Theme">
MyPage.cshtml.cs:
using Microsoft.AspNetCore.Mvc.RazorPages;
using System;
namespace MyProject.Pages
{
public class MyPageModel : PageModel
{
public string Theme { get; set; } = "";
public void OnGet()
{
if(showInfo) Theme = "bg-info";
else if(showInfo) Theme = "bg-success";
}
}
}
推荐阅读
- node.js - Firebase 函数在尝试写入存储时抛出错误
- r - R中count.fields函数中的quote =“”是什么意思?
- api - 为什么在资源 ID 的开头使用首字母缩略词?
- css - 如何在 React 中取消单击表格单元格
- python - 为什么这个正则表达式不匹配完整的模式?
- progressive-web-apps - 有什么方法可以阻止用户在 Kiosk 设备中关闭 PWA 应用程序
- reactjs - 组件在反应中被渲染 6 次
- python - 如何在pyspark中将类型从_csv.reader转换为rdd
- sql - 如何计算所有记录并提取上次活动日期
- c++ - 具有格式错误的默认模板参数的未使用成员模板是否需要诊断?