2013-06-13 46 views
-1

我正在從文本文件中讀取博客文章的內容,它是html格式,我想在頁面上將它們顯示爲呈現的html,但並未發生其全部顯示爲帶有html標籤等的簡單文本。 我已經嘗試了三種可能的方法,我知道讓它工作,但所有的人都出現了不渲染HTML:如何從視圖中的編碼HTML字符串呈現HTML元素?

<section id="content"> 
    @Server.HtmlDecode(content[2]) 
    @content[2] 
    @MvcHtmlString.Create(content[2]) 
    @Html.Raw(content[2]) 
</section> 

內容[2]包含HTML文本:

"&lt;p itemprop=\"articleBody\" style=\"font-size:1.5em;line-height:1.467em;font-family:georgia, 'times new roman', times, serif;text-align:left;\"&gt;The movie, which tells the story of the way the small-market Oakland Athletics used outside-the-box statistical analysis to compete successfully against talent-rich competition, resonated with Snedeker, who is not the longest, straightest or most accurate hitter in golf.&lt;/p&gt 

其顯示爲:

<p itemprop="articleBody" style="font-size:1.5em;line-height:1.467em;font-family:georgia, 'times new roman', times, serif;text-align:left;">The movie, which tells the story of the way the small-market Oakland Athletics used outside-the-box statistical analysis to compete successfully against talent-rich competition, resonated with Snedeker, who is not the longest, straightest or most accurate hitter in golf.</p> 

如果問題是因爲保存的內容是不實際的避風港從< &打開右括號,但他們有他們的ascii代碼,顯示我怎麼能阻止它發生,因爲它只是一個簡單的形式與文本區域,我輸入此內容(使用Kendo UIEditor)和發佈後,當我收到我的控制器它有ascii代碼而不是實際的字符。

回答

1

你試過

<section id="content"> 
    @Html.Raw(content[2]) 
</section> 

這應該停止編碼的HTML的Razor視圖引擎的HTML。

+0

已經試過'@ Html.Raw(content [2])',但沒有效果,所有三個都顯示相同的結果。它的工作原理是 – Maven