显示输出时CKEditor出现问题

时间:2013-09-04 13:52:56

标签: asp.net-mvc ckeditor

我正在使用CKEditor和ASP.NET MVC,但是有一个非常奇怪的问题:如果我有一些错误并且内容必须格式化一些文本(例如应用粗体,使其成斜体或列表)回发到textarea,它显示为HTML文本 - “ul li”等,而不是再次设置样式(粗体,斜体等)。

我在配置中应用了一些选项:

config.htmlEncodeOutput = true; // to avoid text being interpreted as attack

config.enterMode = CKEDITOR.ENTER_BR; // in order not to place tags arround the text 

config.basicEntities = false; // do display spaces as they are instead of   and so on...

我在MVC Server.HtmlDecodeHttpUtility.Decode中尝试了一些内置函数,但似乎没有任何效果。与MVC一起使用的其他编辑器的解决方案也被接受。

这是.cshmtl文件:

@{
    ViewBag.Title = "CkEditor";
}

@model HtmlTextEditorsDemos.Models.SimpleModel

<h2>CkEditor</h2>

<script src="~/Scripts/ckeditor.js"></script>

@using (Html.BeginForm())
{
    @Html.TextAreaFor(x => x.Text, new { @class = "ckeditor" })
    <input type="submit" value="send" />
}

在动作方法中,我只是为了测试目的而再次返回数据:

[HttpPost]
public ActionResult Index(SimpleModel model)
{
    //model.Text = Server.HtmlDecode(model.Text);
    return View(model);
}

SimpleModel类只是一个只有1个属性的测试模型类 - Text。

1 个答案:

答案 0 :(得分:-1)

你可以试试这个

@foreach (var item in Model)
{
    <tr>

        <td>
            @Html.DisplayFor(modelItem => item.Title)
        </td>
        <td>
           @{
    string description = Server.HtmlDecode(item.Description);
           }
            @Html.Raw(description)

        </td>
        <td>
            @Html.DisplayFor(modelItem => item.Note)
        </td>
        <td>
            <img src="~/img/Uploads/@item.Pic" width="150" height="120" />
        </td>

    </tr>
}
相关问题