Database field containing HTML display raw text

2019-07-17 15:17发布

ASP.Net MVC3 using c#

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)

Currently the HTML is being displayed as plain text how do I get it to render the HTML properly?

1条回答
Luminary・发光体
2楼-- · 2019-07-17 16:05

You mean without HTML encoding it? You could use the Html.Raw helper:

@Html.Raw(Model.game_description)

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.

查看更多
登录 后发表回答