zoukankan      html  css  js  c++  java
  • 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 = "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
    认真工作、认真生活,努力做最好的自己!!!
  • 相关阅读:
    tornado之运行第一个tornado程序
    Django之QuerySet 查询
    openstack之路:KVM/Libvirt 安装
    【原创】Linux基础之SSH隧道/端口转发
    【原创】运维基础之keepalived
    【原创】数据库基础之Mysql(2)主从库配置
    【原创】Linux基础之iptables
    【原创】大叔经验分享(28)ELK分析nginx日志
    【原创】算法基础之Anaconda(1)简介、安装、使用
    【原创】大数据基础之Airflow(1)简介、安装、使用
  • 原文地址:https://www.cnblogs.com/songhuihui/p/12377169.html
Copyright © 2011-2022 走看看