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"] = 0; hash["url"] = "请选择文件"; return Json(hash); } string dirPath = Server.MapPath(savePath); if (!Directory.Exists(dirPath)) { hash = new Hashtable(); hash["error"] = 0; hash["url"] = "上传目录不存在"; 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"] = 0; hash["url"] = "上传文件大小超过限制"; return Json(hash); } if (string.IsNullOrEmpty(fileExt) || Array.IndexOf(fileTypes.Split(','), fileExt.Substring(1).ToLower()) == -1) { hash = new Hashtable(); hash["error"] = 0; hash["url"] = "上传文件扩展名是不允许的扩展名"; 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"); ; } } }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值