样本:
@{
var s = "<p>Sample text</p>";
}
期待:
Sample text.
我希望它在浏览器上呈现,但我无法呈现它。它只是将 s 的整个值输出为文本字符串。我已经试过了
@(new HtmlString(s))
用
HttpUtility.HtmlEncode
对其进行编码并用 HttpUtility.HtmlDecode
解码但还是没有用。
最佳答案
你会需要
<div >@((MarkupString)s)</div>
@code
{
string s = "<p>Sample text</p>";
}
<p>
将在 <div>
内呈现
关于blazor - 将带有 html 标签的纯文本转换为 html 字符串并在 Blazor 中呈现它,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60167219/