码迷,mamicode.com
首页 > 其他好文 > 详细

KindEditor 编辑器前台得使用规范

时间:2020-02-28 15:44:43      阅读:74      评论:0      收藏:0      [点我收藏+]

标签:turn   one   ati   hidden   htable   click   编辑器   ted   isp   

官方网址:http://www.kindsoft.net/
下载网址:http://www.kindsoft.net/down.php

 引入得脚本:

<link href="~/Content/kindeditor/themes/default/default.css" rel="stylesheet" />
<script src="~/Content/kindeditor/kindeditor-min.js"></script>
<script src="~/Content/kindeditor/lang/zh_CN.js"></script>
<script src="~/Content/kindeditor/plugins/code/prettify.js"></script>
<script src="~/Content/JS/KindEditor.js"></script>

html:

@Html.TextAreaFor(model => model.Content, new
{
id = "content1",
cols = "100",
rows = "8",
Style = "width:99%;height:370px;visibility:hidden;"
})

KindEditor.js

KindEditor.ready(function (K) {
var editor1 = K.create(‘#content1‘, {
uploadJson: ‘/Home/UploadImage‘,
fileManagerJson: ‘../asp.net/file_manager_json.ashx‘,
allowFileManager: false,
afterCreate: function () {
var self = this;
K.ctrl(document, 13, function () {
self.sync();
K(‘form[name=example]‘)[0].submit();
});
K.ctrl(self.edit.doc, 13, function () {
self.sync();
K(‘form[name=example]‘)[0].submit();
});
}
});
prettyPrint();
});

Home/UploadImage:

技术图片
 1 public ActionResult UploadImage()
 2 {
 3 string savePath = "/Upload/";
 4 string saveUrl = "/Upload/";
 5 string fileTypes = "gif,jpg,jpeg,png,bmp,zip,rar,pdf,doc ";
 6 int maxSize = 1000000000;
 7 Hashtable hash = new Hashtable();
 8 HttpPostedFileBase file = Request.Files["imgFile"];
 9 if (file == null)
10 {
11 hash = new Hashtable();
12 hash["error"] = 0;
13 hash["url"] = "请选择文件";
14 return Json(hash);
15 }
16 string dirPath = Server.MapPath(savePath);
17 if (!Directory.Exists(dirPath))
18 {
19 hash = new Hashtable();
20 hash["error"] = 0;
21 hash["url"] = "上传目录不存在";
22 return Json(hash);
23 }
24 
25 string fileName = file.FileName;
26 string fileExt = Path.GetExtension(fileName).ToLower();
27 ArrayList fileTypeList = ArrayList.Adapter(fileTypes.Split(,));
28 if (file.InputStream == null || file.InputStream.Length > maxSize)
29 {
30 hash = new Hashtable();
31 hash["error"] = 0;
32 hash["url"] = "上传文件大小超过限制";
33 return Json(hash);
34 }
35 string newFileName = DateTime.Now.ToString("yyyyMMddHHmmss_ffff", DateTimeFormatInfo.InvariantInfo) + fileExt;
36 string filePath = dirPath + newFileName;
37 file.SaveAs(filePath);
38 string fileUrl = saveUrl + newFileName;
39 hash = new Hashtable();
40 hash["error"] = 0;
41 hash["url"] = fileUrl;
42 return Json(hash, "textml;charset=UTF-8"); ;
43 }
View Code

KindEditor 编辑器前台得使用规范

标签:turn   one   ati   hidden   htable   click   编辑器   ted   isp   

原文地址:https://www.cnblogs.com/songhuihui/p/12377169.html

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