1

と一緒に CKEditor を使用してASP.NET MVCいますが、非常に奇妙な問題があります。エラーが発生し、コンテンツをテキストエリアにポストバックする必要があるときにテキストをフォーマットすると (太字にする、イタリックにする、リストにするなど)、 HTML テキスト (太字、イタリック体など) ではなく、"ul li" などのように表示されます。

config にいくつかのオプションを適用しました。

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...

MVClikeでいくつかの組み込み関数を試しましたが、何も機能し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) のみを持つ単なるテスト モデル クラスです。

4

1 に答える 1

-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>
}
于 2015-11-02T08:50:52.803 に答える