2013-12-23 69 views
0

我希望編輯器可以編碼,因爲我想將編輯器文本發佈到控制器,但我發現當我刷新頁面(單擊F5)時,編輯器會再次對文本進行編碼。我的Model.Body也包含html標記:For例如,第一次進入頁面是確定的,並顯示「我的模型正文在這裏」,我刷新頁面,它顯示如下的html標記,但我只想編碼一次,我也不使用緩存,但它不要work.Third時間我刷新頁面,再次進行編碼,並顯示<table><tbody>...如何在kendoui編輯器中避免重複編碼?

型號

//after search,my Model.Body is here 
<table> 
<tbody> 
<tr><td align="center" style="font-weight:bold;"> 
<span style="background-color:#ccff33;">My Model Body Is Here</span> 
</td></tr> 
</tbody> 
</table> 

查看

@(Html.Kendo().Editor() 
    .Name("Body") 
    .Tools(tools => tools.Clear() 
    .Bold().Italic().Underline().Strikethrough() 
    .JustifyLeft().JustifyCenter().JustifyRight().JustifyFull() 
    .InsertUnorderedList().InsertOrderedList() 
    .Outdent().Indent() 
    .CreateLink().Unlink() 
    .InsertImage() 
    .SubScript() 
    .SuperScript() 
    .ViewHtml() 
    .FontName() 
    .FontSize() 
    .FontColor().BackColor() 
    ) 
    .HtmlAttributes(new { style = "width:90%;height:500px" }) 
    .Value(Model.Body)) 

控制器

[OutputCache(Duration = 0)] 
public ActionResult Index(int id=0) 
{ 
return View(ModelRepository.GetModelById(id)); 
} 

回答

1

這是由編輯器的默認編碼引起的,當從瀏覽器bfcache獲取頁面時。爲了解決這個問題,在視圖中設置Encoded(false),並通過設置[AllowHtml]屬性指出該字段將在模型中包含HTML。另一方面,您可以放棄bfcache。

0

試着在你的編輯器設置.Encode(false)。當顯示內容時,您可能需要做@Html.Raw(Model.Content)