本文介绍了写作/ HTML输出转义字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我得保存在一个数据库表安全/消毒的HTML。
I've got safe/sanitized HTML saved in a DB table.
我怎么可以在一个的Razor视图写出这样的HTML内容?
How can I have this HTML content written out in a Razor view?
它总是转义字符,如<
和&符号为&放大器;放大器;
It always escapes characters like <
and ampersands to &
.
推荐答案
假设你的内容是一个名为字符串中的myString
...
Supposing your content is inside a string named mystring
...
您可以使用:
@Html.Raw(mystring)
另外,您可以将您的字符串,<$c$c>HtmlString$c$c>或任何其他类型实现 IHtmlString
模型或直接内嵌和使用常规 @
:
Alternatively you can convert your string to HtmlString
or any other type that implements IHtmlString
in model or directly inline and use regular @
:
@{ var myHtmlString = new HtmlString(mystring);}
@myHtmlString
这篇关于写作/ HTML输出转义字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!