MVC中使用Ueditor

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

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

141726504749679.png

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

141726509213752.png

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>
使用文本编辑器的区域框
141726515322339.png
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(){})

141726520486195.png

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

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值