Watch video

You will take a look at how you can prevent HTML encoding when outputting with a @. ** 
When you display content in a page using the **@
 character, ASP.NET will HTML encode this output. This replaces the reserved HTML character, such as a \< and > sign, with codes that **enable the characters **to be displayed as characters in a webpage, instead of being interpreted as HTML tags or entities. Of course, sometimes you don't want this behavior and you want to output unencoded.

To output unencoded, use @Html.Raw() - here is an example:

In your statement, you have created a variable someHtml and a string that contains a paragraph tag, a strong tag - then, you output your variable by using the @ and the name of your variable.

Go to your front end and take a look at the output.

As you can see, the output is encoded. ** 
If you take a look at the page source, you can see that the HTML characters **have been replaced with codes
, meaning that the output has been HTML encoded .

To get the unencoded value, just add @Html.Raw, providing it with your variable.

Save your template and refresh your front end. *Your tags have been rendered as they should. *

Let's review this chapter.

  • *To output unencoded, use @Html.Raw(). *

Razor Syntax

Total Time: 00:28:02

Introduction to the razor syntax with examples on how to write code blocks, inline expressions, comments, variables, conditional logic, loops,...