GibboK
GibboK

Reputation: 73908

How Decode HTML in MVC with RAZOR

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

Upvotes: 3

Views: 3946

Answers (3)

Abhay Narayan
Abhay Narayan

Reputation: 29

Use is @MvcHtmlString.Create(@Model.OurVision)

Upvotes: 1

amd
amd

Reputation: 21442

you can use to output the data as is without encoding :

@Html.Raw(model.Code)

Upvotes: 1

heads5150
heads5150

Reputation: 7443

To display raw html use

@Html.Raw(model.Code)

Be extremely careful though

Upvotes: 3

Related Questions