【问题标题】:Embed executable Blazor code into a JSON input string将可执行的 Blazor 代码嵌入到 JSON 输入字符串中
【发布时间】:2020-07-11 07:50:27
【问题描述】:

我有以下 Blazor 代码,其中数据值是从 JSON 文件输入的。

<p>@product.Name</p>
<p>@((MarkupString)product.Description)</p>

我想做的是将@product.Name 嵌入到 JSON 文件的描述文本中,以便将其呈现为描述的一部分。 我正在寻找这样简单的东西:

"Description": "This a detailed description of the <dummytag>@product.Name</dummytag> product or service".

我尝试了各种组合,但无法呈现 gen3Product.Name。 谁能告诉我如何做到这一点,拜托。 我知道这会导致糟糕的安全结果。

【问题讨论】:

    标签: html razor blazor blazor-server-side


    【解决方案1】:

    在 Blazor 中,@product.Name 必须在部署之前进行编译。因此,将其嵌入到您的数据中是行不通的。

    不过,您可以使用旧式字符串格式:

     "Description": "This a detailed description of the <dummytag>{0}</dummytag> product or service"
    

    然后

     <p>@((MarkupString) string.Format(product.Description, product.Name)</p>
    

    但这显然不够灵活。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-11-13
      • 1970-01-01
      • 1970-01-01
      • 2021-05-02
      • 1970-01-01
      • 2010-11-09
      相关资源
      最近更新 更多