如何防止ckeditor不保存HTML标签,而只保存富文本 [英] How to prevent ckeditor not saving HTML tags , but just the rich text

查看:95
本文介绍了如何防止ckeditor不保存HTML标签,而只保存富文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请附上我的问题的HTML代码和打印屏幕。当我在ckeditor中编写内容并使用html标签应用样式时,它使用HTML标记保存文本,而不仅仅是文本本身,在这种情况下只是内容样本文本。它还为背景中的某些html标签应用样式,并且不会显示它们像< pre>< p>内容样本文本< / p>





Please find attached the html code and the printscreen of my problem. When I write something in ckeditor, and apply styling with html tags, it saved the text with HTML tags, and not just the text itself, in this case just CONTENT SAMPLE TEXT. It also applies the styling for certain html tags in backgound, and does not show them like <pre><p>CONTENT SAMPLE TEXT</p>


<div class="form-group">
      @Html.LabelFor(model => model.LongDescription1, htmlAttributes: new { @class = "control-label col-md-2" })
      <div class="col-md-10">

         @Html.TextAreaFor(model => model.LongDescription1, new { @id = "LongDescription1", @class = "form-control", @rows = "200" })



          @Html.ValidationMessageFor(model => model.LongDescription1, "", new { @class = "text-danger" })
          CKEDITOR.replace("LongDescription1", { htmlEncodeOutput: true });


      </div>
  </div>





我的尝试:



没有提到海报尝试的内容。



What I have tried:

No mention is made of what the poster has tried.

推荐答案

CKEditor是基于HTML的编辑。您使用HTML标签及其属性获得的所有丰富性......如果删除HTML部分,您将获得纯文本...
CKEditor is a HTML based editor. All the richness you see gained using HTML tags and their attributes... If you remove the HTML part you get plain text...


如果我已正确理解您的评论,则问题不是编辑 HTML,而是再次显示



使用时:
If I've understood your comment correctly, the problem is not with editing the HTML, but with displaying it again.

When you use:
@Model.LongDescription1

输出自动进行HTML编码。这是为了防止跨站点脚本漏洞。



所以,如果你输入了:这个是一个测试,输出将是:< b>这< / b>是< i>测试< / i>



到将您的输出视为HTML,您需要使用 Html.Raw [ ^ ]助手:

the output is automatically HTML-encoded. This is to protect against cross-site scripting vulnerabilities.

So, if you've entered: "This is a test", the output will be: "<b>This</b> is a <i>test</i>"

To have your output treated as HTML, you need to use the Html.Raw[^] helper:

@Html.Raw(Model.LongDescription1)



注意:你需要确保用户无法将恶意HTML / Javascript注入其他用户的视图。


NB: You will need to ensure that users are not able to inject malicious HTML / Javascript into other users' views.


这篇关于如何防止ckeditor不保存HTML标签,而只保存富文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆