html编码/解码-ckeditor [英] html encode/decode - ckeditor
问题描述
我在cshtml页面中使用ckeditor将内容输入到数据库中,该内容稍后将显示在带有html标签的页面上,以使文本更易于阅读。由于我是通过文本区域输入内容的,因此我收到一条错误消息,指出我输入的< h1>< p>
html标签有潜在的危险。
I am using ckeditor in a cshtml page to input content into my database that will later be displayed on a page with html tags to make the text easier to read. Since I am inputting the content through a textarea, I am getting a an error stating that the html tags that I am inputting <h1><p>
are potentially dangerous.
要在不将RequestValidation设置为false的情况下绕过它,请在我的cinfig.js文件中设置:
To bypass this without turning RequestValidation to false, in my cinfig.js file I have set:
config.htmlEncodeOutput = true;
在页面中显示时,我正在解码数据库中的数据。
I am decoding the data from the database when displaying in my page.
@Html.Raw(System.Web.HttpUtility.HtmlDecode(row.Memo))
这很好。我只是在尝试第二次编辑数据库中的内容时遇到麻烦。
This works well. I only run into trouble when I attempt to edit the content from my database a second time.
我在编辑器中这样显示:
I am displaying in the editor like this:
<textarea class="ckeditor" id="editor1" name="Memo" rows="25" cols="120">@Memo</textarea>
在文本区域中使用 @Memo
当前数据库内容显示在编辑器中。问题是,一旦将原始文本编码后发送到数据库,我相信当在编辑器中重新显示它并需要对其进行解码时,它仍然会被编码。因此,编辑器将编码后的标签视为文本,并在现有标签周围放置新标签,这会造成混乱。
With @Memo
in the textarea, the current database content displays in the editor. The issue is that once the original text is sent to the database encoded, I believe that it is still encoded when re-displayed in the editor, when it needs to be decoded. So the editor treats the encoded tags as text and places new tags around the existing, which creates a mess.
任何想法都将不胜感激。让我知道是否需要进一步说明。
Any ideas would be greatly appreciated. Let me know if this needs more clarification.
谢谢。
推荐答案
提交问题后,我给了这个公正的思想。
I gave this JUST the right amount of thought JUST after I submitted this question.
我使用了 @ Html.Raw(System.Web.HttpUtility .HtmlDecode(row.Memo))
解码要显示在页面上的数据,因此我能够使用 @ Html.Raw(System.Web.HttpUtility.HtmlDecode (备忘录))
代替 @备忘录
以在编辑器中显示,从而纠正了我的问题。
I used @Html.Raw(System.Web.HttpUtility.HtmlDecode(row.Memo))
to decode the data to be displayed on the page, so I was able to use @Html.Raw(System.Web.HttpUtility.HtmlDecode(Memo))
in place of @Memo
to display in the editor, which corrected my issue.
这篇关于html编码/解码-ckeditor的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!