10

Does ASP.NET MVC razor view engine encode HTML by default?

Or do we have to use the htmlhelpers for html encoding the data.

ckv
  • 10,539
  • 20
  • 100
  • 144
  • It is apparently on by default, as there are questions [asking how to turn it off](http://stackoverflow.com/q/4973504/102937). – Robert Harvey Jun 10 '13 at 15:43

2 Answers2

14

Yes it does. Use @Html.Raw(...) to break that behavior.

Daniel A. White
  • 187,200
  • 47
  • 362
  • 445
1

Or use HttpUtility.HtmlDecode

string value1 = "<html>";                 // <html>
string value2 = HttpUtility.HtmlDecode(value1); // <html>
wuhcwdc
  • 286
  • 1
  • 10