2012-09-07 26 views
0

我有一個存儲html的db字段,我想在用戶端呈現該html。但我無法這樣做。當我試圖把HTML標籤或段落標籤,然後我只是HTML文本。這裏是我的代碼,我試圖MVC中的div標記中呈現HTML 3

<%: 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> 

回答

6

嘗試使用Html.Raw輸出你的HTML:

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

thanx ....它的工作! –

+0

@AnkushJain如果他幫助解決您的問題,請考慮獎勵Marek,並將他的回答標記爲已接受。 :) – Kjartan

2

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