razor-pages - Razor Pages - 动态添加元刷新标签
问题描述
使用 DotNetCore 2.2。
我想动态地向我的 Razor 页面添加元刷新。
<head>
...
<meta http-equiv="refresh" content="30">
</head>
IE
public async Task OnGet()
{
if (something) {
// add the meta tag
}
}
我的 _Layout 目前是新项目的默认布局。
解决方案
也许有一种更优雅的方式来做到这一点。
但我去了——
public async Task OnGet()
{
if (something) {
// add the meta tag
ViewData["ShowMeta"] = _refreshSeconds.ToString();
}
}
在 _Layout.cshtml
@if (ViewData["ShowMeta"] != null)
{
<meta http-equiv="refresh" content="@ViewData["ShowMeta"]">
}
推荐阅读
- java - 无法获得 mouseClicked 以随机播放不同的图像
- apache-spark - 将 kafka 主题中的数据读入 spark 数据框
- vhdl - 尝试编译 VHDL 代码时,“架构”内发生错误
- flutter - 如何以 CircularNotch 为中心制作 Flutter BottomAppBar?
- java - 使用 Java Hibernate,当复合键的一部分是主键的一部分时,如何使用可为空的复合外键?
- c# - 如何在 Unity 的第一人称射击游戏中进行刚体运动?
- python - 通过连接来自 n 个相邻行的字符串值来折叠 DataFrame
- matlab - MATLAB 单个图中的多个箱形图
- php - 将输入从“GET”发送到php中的xml文件
- c++ - 如何设置(而不是构建)PortAudio?