3

I'm using MVC 3 and Razor as View Engine, for my understanding HTML tags are decoding by default to prevent XSS attacks or similar. (I'm also using MS XSS 4.2.1 Library)

I have a View showing some data

<div class="display-label">Code</div>
<div class="display-field">
    @Html.DisplayFor(model => model.Code).
</div>

Model.Code is HTML code for some Banners, I need to display the HTML on the page DECODED. My question: How can I decode the HTML for just model.Code living the rest ENCODED?

Thanks for your help

4

3 回答 3

3

To display raw html use

@Html.Raw(model.Code)

Be extremely careful though

于 2012-07-03T06:50:20.810 回答
1

用途是@MvcHtmlString.Create(@Model.OurVision)

于 2014-02-07T08:07:07.680 回答
1

您可以使用原样输出数据而无需编码:

@Html.Raw(model.Code)
于 2012-07-03T06:51:30.763 回答