在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 3 Razor 视图引擎 中使用@输出的内容都会被自动进行HTML编码 问题的解决办法
- 关于asp.net mvc 使用ueditor添加内容 前端只显示原样标签的问题
- ASP.NET MVC 给ViewBag赋值Html格式字符串的显示问题总结
- ASP.NET MVC Razor 输出没有编码的HTML字符串
- ASP.NET CORE中控制器内return HTML 内容自动编码问题
- ASP.NET MVC Razor 输出没有编码的HTML字符串
- ASP.NET CORE中控制器内return HTML 内容自动编码问题
- [ASP.net MVC] 将HTML转成PDF档案,使用iTextSharp套件的XMLWorkerHelper (附上解决显示中文问题)
- asp.net MVC中使用Html.Checkbox提示该字符串未被识别为有效的布尔值错误的解决方法
- 关于在ASP.NET MVC 中使用EF的Code First的方式来读取数据库时的Validation failed for one or more entities. See 'EntityValidationErrors' property for more details.
- 【ASP.NET】传值问题及读取数据库内容——补充
- 关于asp.net MVC发布后,网站无法读取数据库的问题
- asp.net使用unescape读取js escape编码过的字符串
- ASP.NET MVC 给ViewBag赋值Html格式字符串的显示问题总结
- 使用ASP.NET MVC 2编程时遇到的两个小问题
- ASP.NET MVC Razor 输出没有编码的HTML字符串
- ASP.NET MVC学习时,自动导入数据库控制器和视图时遇到的问题
- ASP.NET Core解决MVC视图中的中文被html编码的问题
- asp.net mvc 2 简简单单做开发 使用DataContext扩展方法Find<TEntity>(TEntity obj) 遇到的问题
- ASP.NET MVC 给ViewBag赋值Html格式字符串的显示问题总结