Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to write html field on asp.net MVC3 Razor

I've a String field on my model that contains an html value, my problem is that when I place the code to render this field on my view it will be entirely reconverted to html, and the final result is a big string with html characters escaped...

@field //= "<div>"

renders

 &lt ;div&gt ;

How can i override this behavior and force it to write the html unescaped on my field?

like image 546
Flavio CF Oliveira Avatar asked Nov 07 '11 09:11

Flavio CF Oliveira


2 Answers

You could use the Html.Raw helper:

@Html.Raw(field)
like image 190
Darin Dimitrov Avatar answered Oct 03 '22 18:10

Darin Dimitrov


Use @Html.Raw:

@Html.Raw(field)
like image 22
Richard Dalton Avatar answered Oct 03 '22 18:10

Richard Dalton