问题
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
回答1:
To display raw html use
@Html.Raw(model.Code)
Be extremely careful though
回答2:
you can use to output the data as is without encoding :
@Html.Raw(model.Code)
回答3:
Use is @MvcHtmlString.Create(@Model.OurVision)
来源:https://stackoverflow.com/questions/11305787/how-decode-html-in-mvc-with-razor