将带有html标记的纯文本转换为html字符串并在Blazor中呈现 [英] Convert plain text with html tags to html string and render it in Blazor
本文介绍了将带有html标记的纯文本转换为html字符串并在Blazor中呈现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
示例:
@{
var s = "<p>Sample text</p>";
}
期望:
示例文本.
我希望它在浏览器中呈现,但无法呈现.它仅将s的整个值作为文本字符串输出.我已经尝试了
I want it rendered on browser but I couldn't render it. It just outputs the whole value of s as text string. I already try
@(new HtmlString(s))
使用 HttpUtility.HtmlEncode
对其进行编码,并使用 HttpUtility.HtmlDecode
对其进行解码,但仍然没有用.
encoded it with HttpUtility.HtmlEncode
and decode it with HttpUtility.HtmlDecode
but still no use.
推荐答案
您将需要
<div >@((MarkupString)s)</div>
@code
{
string s = "<p>Sample text</p>";
}
< p>
将在< div>
这篇关于将带有html标记的纯文本转换为html字符串并在Blazor中呈现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文