我有一个关于在ASP中使用WYMEditor的问题。NET MVC 3与jQuery。我想在我的网页上设置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等,但它仍然不工作。
试试:
<script type="text/javascript">
jQuery(function() {
var html = @Html.Raw(Json.Encode(ViewBag.HtmlText));
jQuery('.wymeditor').wymeditor({ html: html });
});
</script>
请摆脱这个ViewBag
,因为每次我看到它我生病。使用视图模型和强类型视图