asp.net MVC使用kindeditor编辑器

直接在aspx页面里写入这么一句话

<mce:script src="/Content/kindeditor/kindeditor.js" mce_src="Content/kindeditor/kindeditor.js" charset="utf-8" type="text/javascript"></mce:script>  

<mce:script type="text/javascript"><!--  

    KE.show({  

        id: 'MainContent_content',  

        imageUploadJson: '/upload/uploadimage',  

        fileManagerJson: '/Content/kindeditor/asp.net/file_manager_json.aspx',  

        allowFileManager: true,  

        allowUpload: true,  

        afterCreate: function (id) {  

            KE.event.ctrl(document, 13, function () {  

                KE.util.setData(id);  

            });  

            KE.event.ctrl(KE.g[id].iframeDoc, 13, function () {  

                KE.util.setData(id);  

            });  

        }  

    });  

   

// --></mce:script>  

调用语句:

<textarea id="content" cols="100" rows="8" style="width:100%;height:200px;visibility:hidden;" runat="server">  

若要配置图片上传

贴上图片上传upload的代码

using System;  

using System.Linq;  

using System.Web;  

using System.Web.Mvc;  

using System.IO;  

using System.Globalization;  

using System.Collections;  

namespace nbut.Controllers  

{  

    public class uploadController : Controller  

    {  

        [HttpPost]  

        public ActionResult UploadImage()  

        {  

            string savePath = "/upload/news/";  

            string saveUrl = "/upload/news/";  

            string fileTypes = "gif,jpg,jpeg,png,bmp";  

            int maxSize = 1000000;  

            Hashtable hash = new Hashtable();  

            HttpPostedFileBase file = Request.Files["imgFile"];  

            if (file == null)  

            {  

                hash = new Hashtable();  

                hash["error"] = 1;  

                hash["message"] = "请选择文件";  

                return Json(hash);  

            }  

            string dirPath = Server.MapPath(savePath);  

            if (!Directory.Exists(dirPath))  

            {  

                hash = new Hashtable();  

                hash["error"] = 1;  

                hash["message"] = "上传目录不存在";  

                return Json(hash);  

            }  

            string fileName = file.FileName;  

            string fileExt = Path.GetExtension(fileName).ToLower();  

            ArrayList fileTypeList = ArrayList.Adapter(fileTypes.Split(','));  

            if (file.InputStream == null || file.InputStream.Length > maxSize)  

            {  

                hash = new Hashtable();  

                hash["error"] = 1;  

                hash["message"] = "上传文件大小超过限制";  

                return Json(hash);  

            }  

            if (string.IsNullOrEmpty(fileExt) || Array.IndexOf(fileTypes.Split(','), fileExt.Substring(1).ToLower()) == -1)  

            {  

                hash = new Hashtable();  

                hash["error"] = 1;  

                hash["message"] = "上传文件扩展名是不允许的扩展名";  

                return Json(hash);  

            }  

            string newFileName = DateTime.Now.ToString("yyyyMMddHHmmss_ffff", DateTimeFormatInfo.InvariantInfo) + fileExt;  

            string filePath = dirPath + newFileName;  

            file.SaveAs(filePath);  

            string fileUrl = saveUrl + newFileName;  

            hash = new Hashtable();  

            hash["error"] = 0;  

            hash["url"] = fileUrl;  

            return Json(hash, "text/html;charset=UTF-8"); ;  

        }  

    }  

}  

 

 

你可能感兴趣的:(kindeditor)