2011-07-10 75 views
0

我有一個關於在ASP.NET MVC 3中使用WYMEditor和jQuery的問題。我想在我的網頁上設置WYMEditor的默認文本。如果我以這種方式正在做:在WYMEDITOR中設置默認文本

<script type="text/javascript"> 
jQuery(function() { 
    jQuery(".wymeditor").wymeditor({ html : '<strong>some text</strong>'}); 
}); 

是沒有問題的,並且wymeditor顯示良好的格式化文本,但我嘗試以這種方式:

<script type="text/javascript"> 
jQuery(function() { 
    jQuery(".wymeditor").wymeditor({ html : '@ViewBag.HtmlText'}); 

}); 

(htmlText都將是變量,其中我保持:<strong>some text</strong>)WymEditor顯示我沒有格式化文本<strong>some text</strong>。我試過HtmlEncoding等,但它仍然無法正常工作。

回答

1

嘗試這樣的:

<script type="text/javascript"> 
    jQuery(function() { 
     var html = @Html.Raw(Json.Encode(ViewBag.HtmlText)); 
     jQuery('.wymeditor').wymeditor({ html: html }); 
    }); 
</script> 

並請擺脫這種ViewBag因爲每次我看到我生病的。使用視圖模型和強類型視圖。

+0

我有不同的視圖模型,但這只是一個簡單的例子。多謝。 – jacbar

+0

@jacbar,它工作嗎? –

+0

是的,它的工作 – jacbar

相關問題