0

I've read What is an MvcHtmlString and when should I use it? I did not understand the whole answer of Torbjörn Nomell. He wrote that "razor encodes everything by default." What does this mean?

Community
  • 1
  • 1
Denis
  • 13
  • 5

1 Answers1

3

He means that Razor will HTML-encode special characters. e.g.:

@{
    var test = "<br>";
}

@test

Will yield:

&lt;br&gt;

If you want to write out the raw HTML (e.g. you are trying to render rich text with HTML formatting) you need to use Html.Raw:

@Html.Raw(test);

Yields:

<br>
Ant P
  • 24,820
  • 5
  • 68
  • 105