您的位置:首页 > 编程语言 > ASP

在asp.net mvc中使用百度UEditor初始化内容遇到自数据库中读取的html字符串在UEditor中始终是html编码的问题

2016-09-13 09:58 916 查看
<script id="Content" name="Content" type="text/plain" style="width: 650px; height: 500px;">
@Model.Content
</script>

这个应该在UEditor被显示为文档形式而不是html源码。刚开始以为是UEditor哪个地方设置不对。于是进行了尝试:

UE.getEditor('Content').ready(function() {
//this是当前创建的编辑器实例
this.setContent('@Model.Content')
})

问题依旧。

采用UE.getEditor('Content',{initialContent:'@Model.Content'}),仍是同样的问题,网上进行了各种搜索,似乎没人和我遇到的问题相似,始终找不到答案。

后来我把数据库中的content字段中的内容直接复制出来然后写入

<script id="Content" name="Content" type="text/plain" style="width: 650px; height: 500px;">
<p style="margin: 12px 0px; padding: 0px; font-family: 微软雅黑; color: rgb(0, 0, 0); font-size: 16px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 28.7999992370605px; orphans: auto; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255);">和中华民族传统佳节中秋节即将到来。今天上午,自治区2016年古尔邦节茶话会在新疆迎宾馆举行,各族各界代表欢聚一堂,共庆佳节。自治区党委书记、新疆生产建设兵团党委第一书记、第一政委陈全国发表了热情洋溢的讲话,代表自治区党委、政府,向全区各族穆斯林群众致以良好的祝愿,向全区各族干部群众和所有关心支持新疆工作的各界人士致以美好的祝福。</p><p style="margin: 12px 0px; padding: 0px; font-family: 微软雅黑; color: rgb(0, 0, 0); font-size: 16px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 28.7999992370605px; orphans: auto; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255);">   一杯清茶香、共话团结情。今天的新疆迎宾馆会议中心暖意浓浓,到处洋溢着欢乐祥和的节日气氛。</p><p style="margin: 12px 0px; padding: 0px; font-family: 微软雅黑; color: rgb(0, 0, 0); font-size: 16px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 28.7999992370605px; orphans: auto; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255);">   茶话会前,陈全国等自治区领导与各族各界代表亲切握手、互致祝福。</p><p style="margin: 12px 0px; padding: 0px; font-family: 微软雅黑; color: rgb(0, 0, 0); font-size: 16px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 28.7999992370605px; orphans: auto; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255);">   自治区党委副书记、自治区主席雪克来提 扎克尔主持茶话会。自治区和兵团领导乃依木 亚森、努尔兰阿不都满金、孙金龙、朱海仑、黄卫、肖开提 依明、熊选国、徐海荣、哈尼巴提 沙布开、李学军、马学军、彭家瑞、刘新齐等出席茶话会。</p><p><br/></p>
</script>
这次正确显示出来了。看来找问题的方向错了。不是UEdior的问题,而是mvc在页面中显示的问题。

先后试用了:

@Model.Content呈现,无效

@Html.DisplayFor(m=>m.Content)无效

@Html.ValueFor(m=>m.Content)无效
各种尝试,没一个起作用的

甚至创建了一隐藏字段,在数据库中读取Content的内容赋值,通过查看源代码,<都被自动编码为:<  。  >都被编码为:>

这MVC真是蛋疼。后来终于搜索到一个合适的:

<script id="Content" name="Content" type="text/plain" style="width: 650px; height: 500px;">
    @Html.Raw(Model.Content)
</script>

这个没问题了。终于解决了此问题。记录备查
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  asp.net mvc UEditor
相关文章推荐