How Decode HTML in MVC with RAZOR

风流意气都作罢 提交于 2019-12-22 11:07:34

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!