HTML Encoding Strings - ASP.NET Web Forms VS Razor View Engine

Chase Florell picture Chase Florell · Nov 13, 2010 · Viewed 25k times · Source

I'm not quite sure how this works yet... trying to find documentation.

In my existing app I've got two different ways of rendering strings in my View

<%: model.something %>
<!-- or -->
<%= model.something %>

The first one is html encoded, and the second one is not.

Is there something similarly short in Razor? All I can find is this, which is the encoded version.

@model.something

Answer

Magnus picture Magnus · Mar 10, 2011

I guess the best approach would be to use the Raw extension-method: @Html.Raw(Model.Something)