Database field containing HTML display raw text

2019-07-17 15:35发布

问题:

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:

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.