Raw is a Razor HTML helper method that writes a string directly to the response without HTML encoding it. Use it only when the string is trusted and must be interpreted as markup; otherwise, Razor's normal encoding is safer. section 17.3.3 section 29.1
Rendering trusted markup
Given task = "<strong>Check oil</strong>", writing @Html.Raw(task) produces <li><strong>Check oil</strong></li>, so the task appears in bold. Writing @task instead encodes the tags, displaying them as text. section 17.3.3
Treat Raw as an exception to Razor's normal output behavior:
- Avoid passing user input, or values derived from user input, to Html.Raw; embedded script can execute in other users' browsers. section 29.1
- Prefer ordinary Razor expressions such as @value when content should appear as text, because Razor HTML-encodes the output. section 29.1
- Prefer Tag Helpers for newer dynamic markup where they provide a clearer, editor-friendly alternative to HtmlHelper methods. section 17.3.3
<li><strong>Check oil</strong></li>
Shows the rendered list item produced when trusted markup is written without encoding. section 17.3.3
