数据库字段包含HTML显示原始文本
问题描述:
ASP.Net MVC3使用C#
ASP.Net MVC3 using c#
目前,我有我的应用程序存储HTML数据库字段,但是当我尝试使用显示HTML领域。
I currently have a database field in my application that stores HTML but when I try to display the HTML field using.
@Html.DisplayFor(model => model.game_description)
目前的HTML被显示为纯文本我怎么得到它正确显示HTML?
Currently the HTML is being displayed as plain text how do I get it to render the HTML properly?
答
您的意思是不HTML编码吗?您可以使用 Html.Raw
助手:
You mean without HTML encoding it? You could use the Html.Raw
helper:
@Html.Raw(Model.game_description)
和警告,并充分了解有关执行此操作的后果:你的网站变得容易受到 XSS攻击。所以一定要确保你知道这个HTML的由来。
And be warned and fully aware about the consequences of doing this: your site becomes vulnerable to XSS attacks. So make sure you know the origin of this HTML.