【问题标题】:Convert plain text with html tags to html string and render it in Blazor将带有 html 标签的纯文本转换为 html 字符串并在 Blazor 中呈现
【发布时间】:2020-05-26 18:20:25
【问题描述】:

示例:

@{
     var s = "<p>Sample text</p>";
 }

期望:

Sample text.

我希望它在浏览器上呈现,但我无法呈现它。它只是将 s 的整个值输出为文本字符串。我已经尝试了

@(new HtmlString(s))

用HttpUtility.HtmlEncode编码,用HttpUtility.HtmlDecode解码,还是没用。

【问题讨论】:

    标签: blazor blazor-client-side


    【解决方案1】:

    你需要

    <div >@((MarkupString)s)</div>
    
    @code
    {
        string s = "<p>Sample text</p>";
    }
    

    &lt;p&gt; 将呈现在 &lt;div&gt; 内

    【讨论】:

    • Google 找不到 MarkupString 关键字。
    猜你喜欢
    • 1970-01-01
    • 2021-12-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-04-21
    • 1970-01-01
    • 2013-08-14
    • 2020-06-11
    相关资源
    最近更新 更多