• 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
    认真工作、认真生活,努力做最好的自己!!!
  • 相关阅读:
    泛在电力物联网建设路线
    如何建设泛在电力物联网?
    泛在电力物联网到底该怎么建?
    泛在电力物联网(能源互联网+物联网)浅析
    泛在电力物联网分析—架构形式
    泛在电力物联网:两个业务 两种发展逻辑
    国网“泛在电力物联网”的战略与逻辑
    MVC中使用Hangfire按秒执行任务
    hangfire 实现已完成的job设置过期,防止数据无限增长
    解决ASP.NET Core部署到IIS,更新项目"另一个程序正在使用此文件,进程无法访问"
  • 原文地址:https://www.cnblogs.com/songhuihui/p/12377169.html
Copyright © 2020-2023  润新知