【问题标题】:Razor Pages - Add Meta Refresh Tag DynamicallyRazor Pages - 动态添加元刷新标签
【发布时间】:2019-12-31 22:02:36
【问题描述】:

使用 DotNetCore 2.2。

我想为我的 Razor 页面动态添加元刷新。

<head>
  ...
  <meta http-equiv="refresh" content="30">
</head>

public async Task OnGet()
{
    if (something) {
        // add the meta tag
    }
}       

我的 _Layout 目前是新项目的默认布局。

【问题讨论】:

    标签: razor-pages


    【解决方案1】:

    也许有更优雅的方式来做到这一点。

    但我选择了-

    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"]">
    }
    

    【讨论】:

      猜你喜欢
      • 2011-12-23
      • 1970-01-01
      • 2019-04-01
      • 2015-07-04
      • 2021-09-28
      • 1970-01-01
      • 2018-10-16
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多