3

我将 Kendo.EditorFor 用于文本框,但在视图中。它显示来自编辑器的 htmls 标签,这是我的控制器:

public ActionResult Create(OpininonModel opininonmodel)
{
    var addOpinion =
        new OpininonModel
        {
            Title=opininonmodel.Title,
            Content=Server.HtmlDecode(opininonmodel.Content),
            Id=opininonmodel.Id,
            IdUser=user,
        };
    db.Opinions.Add(addOpinion);
    db.SaveChanges();
    return RedirectToAction("Index");
}

<strong>123123</strong>认为。我应该HtmlDecode在其他地方还是?

我在我的视图中试过这个:

@(Html.Kendo().EditorFor(model => model.Content).Encode(false))

但这给了我错误:

A potentially dangerous Request.Form value was detected from the client

4

3 回答 3

8

如果您使用 html 帮助程序,您可以在将值从视图接收到控制器后对其进行解码。

它来自他们的文档:这是链接

处理服务器上的编辑器值

编辑器值将作为字符串发布并映射到具有小部件名称的变量。请注意,默认情况下发布的值是 HTML 编码的,以规避 ASP.NET 请求验证。为了解码该值,请使用HttpUtility.HtmlDecode方法。

[HttpPost]
public ActionResult Save(string editor)
{
    string value = HttpUtility.HtmlDecode(editor);

    return View();
}

我想这就是你要找的

于 2013-03-20T12:26:35.907 回答
4

Could you please try with encoded: false

$('.editor').kendoEditor({
     encoded: false
});
于 2013-03-19T18:25:33.087 回答
0

当您使用 $('.editor').kendoEditor() //without encoded:false 时,您应该在控制器中执行以下操作:

model.data = WebUtility.HtmlDecode(model.data);
ModelState.Clear();
于 2015-07-14T00:29:25.577 回答