MVC中使用Ueditor

配置.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\", ""));






附件列表

    原文地址:https://www.cnblogs.com/lujianwei/p/3549903.html