开发者

Setting default text in WYMEDITOR

I've got a question about using WYMEditor in ASP.NET MVC 3 with jQuery. I'd like to set default text in WYMEditor on my web page. If I'm doing in that way :

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

There is no problem, and wymeditor shows well-formated text, but is I try it in that way :

<script type="text/javascript">
jQuery(function() {
   jQuery(".wymeditor").wymeditor( { html 开发者_运维知识库: '@ViewBag.HtmlText'});

 });

(HtmlText is variable where I keep : <strong>some text</strong>) the WymEditor shows me not formated text <strong>some text</strong>. I tried HtmlEncoding and etc, but it stil isn't working.


Try like this:

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

And please get rid of this ViewBag as everytime I see it I get sick. Use view models and strongly typed views.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜