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
I guess the best approach would be to use the Raw extension-method: @Html.Raw(Model.Something)
@Model.Something
automatically HTML encodes. If you want to avoid HTML encoding (and you want this only if you are absolutely sure what you are doing) you could use @MvcHtmlString.Create(Model.Something)
(basically everything that implements IHtmlString won't be encoded). Phil Haack blogged about the Razor view engine syntax.
来源:https://stackoverflow.com/questions/4173483/html-encoding-strings-asp-net-web-forms-vs-razor-view-engine