如何在MVC的模型属性中呈现HTML标签
- 论坛
- 如何在MVC的模型属性中呈现HTML标签
6 浏览
如何在MVC的模型属性中呈现HTML标签
我在数据库表中保存了安全/已过滤的HTML内容。
如何在Razor视图中输出这个HTML内容?
它总是转义一些字符,比如<
和&符号变成了&
。
admin 更改状态以发布 2023年5月23日
匿名的
0 Comments
假设您的内容在名为mystring
的字符串内...您可以使用:
@Html.Raw(mystring)
或者您可以将您的字符串转换为HtmlString
或其它实现IHtmlString
的类型,并在模型或直接内联中使用常规的@
:
@{ var myHtmlString = new HtmlString(mystring);} @myHtmlString
。