KindEditor 编辑器前台得使用规范
官方网址: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-all.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 }