配置.net mvc4项目使用ueditor编辑器。javascript
一、首先下载Ueditor1.3.6开发版(http://ueditor.baidu.com/website/download.html)css
二、将下载的文件放在项目的Content文件夹下,也可放在其余文件加下,但注意将下载的文件夹所有复制到项目中。html
三、项目中配置使用java
引入样式文件web
<link href="~/Content/ueditor/themes/iframe.css" rel="stylesheet" />
引入JS文件mvc
<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
>
数据保存及获取显示时注意事项编辑器
一、保存数据时,对的数据进行编码 Server.HtmlEncode(cmsArc.ArcContent);函数
二、修改时返回数据时须要使用Server.HtmlDecode(cmsArc.ArcContent);对数据进行解码ui
三、数据赋值时注意使用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/","")
五、下面是图片管理配置:
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\\", ""));