簡體   English   中英

在MVC 3中的div標簽中渲染HTML

[英]Render HTML in div tag in MVC 3

我在db中有一個存儲html的字段,我想在用戶端渲染該html。 但是我做不到。 當我嘗試將html放入div標簽或段落標簽中時,我只會得到html文本。 這是我嘗試過的代碼

<%: HttpContext.Current.Server.HtmlDecode(Model.HomePageText) %>

我通過使用它得到以下結果(HTML作為文本出現)

<p> </p> <p style="color: rgb(88, 100, 109); font-family: 'PT Sans', sans-serif; font-size: 13px; line-height: 16px; background-position: -1px -350px; "> Enter custom CSS code into the box below to further customize your mobile site.</p>

嘗試使用Html.Raw輸出HTML:

<div>@Html.Raw(Model.HomePageText)</div>

您需要使用Html.Raw(Model.HomePageText) ,假設您確定不會有任何問題(腳本注入,有害的html等)。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM