码迷,mamicode.com
首页 > Web开发 > 详细

MVC中使用Ueditor

时间:2016-04-14 06:44:06      阅读:277      评论:0      收藏:0      [点我收藏+]

标签:

配置.net mvc4项目使用ueditor编辑器。

1、首先下载Ueditor1.3.6开发版(http://ueditor.baidu.com/website/download.html)

技术分享

2、将下载的文件放在项目的Content文件夹下,也可放在其他文件加下,但注意将下载的文件夹全部复制到项目中。

技术分享

3、项目中配置使用

引入样式文件

<link href="~/Content/ueditor/themes/iframe.css" rel="stylesheet" />

引入JS文件

<script src="~/Content/ueditor/ueditor.config.js"></script>
<script src="~/Content/ueditor/ueditor.all.js"></script>
<script src="~/Content/ueditor/lang/zh-cn/zh-cn.js"></script>
<script src="~/Content/ueditor/ueditor.parse.js"></script>

使用文本编辑器的区域框

技术分享

JS中初始化

<script type="text/javascript">
var editor = new baidu.editor.ui.Editor({
            UEDITOR_HOME_URL: ‘/Content/ueditor/‘,//配置编辑器路径
            iframeCssUrl: ‘/Content/ueditor/themes/iframe.css‘,//样式路径
// initialContent: "@Model.ArcContent",//初始化编辑器内容
            autoHeightEnabled: true,//高度自动增长
            minFrameHeight: 500//最小高度
        });
        editor.render(‘ArcContent‘);//使用文本编辑器的元素

        editor.ready(function () {
var content = ‘@Html.Raw(Model.ArcContent)‘;
            editor.setContent(content);
        });
</script>

数据保存及获取显示时注意事项

1、保存数据时,对的数据进行编码 Server.HtmlEncode(cmsArc.ArcContent);

2、修改时返回数据时需要使用Server.HtmlDecode(cmsArc.ArcContent);对数据进行解码

3、数据赋值时注意使用Html.Raw函数,否者数据会显示为Html标签的形式。使用editor.ready(function(){})

技术分享

修改文件存储的默认路径及无法上传图片和附件的处理办法注意事项

1.把net文件夹下的image.ashx的顶部<%@ Assembly Src="Uploader.cs" %> 和<%@ Assembly Src="Config.cs" %> 

技术分享
2.把net文件夹下的 uploader.cs 上传文件处理方法 public  Hashtable upFile(HttpContext cxt, string pathbase, string[] filetype, int size) 的 pathbase = pathbase + "/"; 改为:pathbase = pathbase + DateTime.Now.ToString("yyyy-MM-dd") + "/";

3.在net文件夹下的 uploader.cs 上传文件处理方法 public  Hashtable upFile(HttpContext cxt, string pathbase, string[] filetype, int size) 的里面加上 uploadpath =uploadpath.Replace("ueditor\\net","");

技术分享

4. 在ueditor.config.js文件中,图片上传配置区把imagePath: URL + "net/" 改为:  imagePath: URL.replace("ueditor/","")

技术分享

5、下面是图片管理配置:
ueditor.config.js文件中,图片在线管理配置区把imageManagerPath: URL + "net/"改为:  imageManagerPath: URL.replace("ueditor/", "")

imageManager.ashx 中,把 DirectoryInfo info = new DirectoryInfo(context.Server.MapPath(path));改为:DirectoryInfo info = new DirectoryInfo(context.Server.MapPath(path).Replace("ueditor\\net\\", ""));

MVC中使用Ueditor

标签:

原文地址:http://www.cnblogs.com/laxknight/p/5389566.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!