標籤:css plugin confirm class file else request pre sha
1.引用樣式和js檔案
<link href="~/Content/scripts/plugins/simditor/css/simditor.css" rel="stylesheet" /><script src="~/Content/scripts/plugins/simditor/js/simditor.js"></script>
2.初始化Simditor
var editor = null; $(function () { //可以參考 http://www.jcodecraeer.com/a/javascript/2015/0201/2393.html editor = new Simditor({ textarea: $(‘#NewsContent‘), placeholder: ‘這裡輸入公告內容...‘, toolbar: [‘title‘, ‘bold‘, ‘italic‘, ‘underline‘, ‘strikethrough‘, ‘color‘, ‘|‘, ‘ol‘, ‘ul‘, ‘blockquote‘, ‘code‘, ‘table‘, ‘|‘, ‘link‘, ‘image‘, ‘hr‘, ‘|‘, ‘indent‘, ‘outdent‘], upload: { url: ‘/PublicInfoManage/Notice/SavePic‘, //檔案上傳的介面地址 params: null, //索引值對,指定檔案上傳介面的額外參數,上傳的時候隨檔案一起提交 fileKey: ‘fileDataFileName‘, //伺服器端擷取檔案資料的參數名 connectionCount: 3, leaveConfirm: ‘正在上傳檔案‘ } }); })
upload設定好就會出現中的選項
實現功能之前需要修改一下引用的js檔案,使用查看瀏覽器的審核元素功能查看,發現input按鈕麼有name屬性
3.開啟Simditor.js檔案搜尋accept屬性,然後添加“name=“fileData”屬性,共有兩處需要添加,如
4.編寫幕後處理圖片代碼
/// <summary> /// 上傳圖片 /// </summary> /// <returns></returns> public ActionResult SavePic() { HttpPostedFileBase file = Request.Files["fileDataFileName"]; if (file != null) { string strPath = HttpContext.Server.MapPath("/Content/Upload/"); if (!Directory.Exists(strPath)) { Directory.CreateDirectory(strPath); } string filePath = Path.Combine(strPath, Path.GetFileName(file.FileName)); file.SaveAs(filePath); return Success("上傳成功!"); } else { return Success("上傳失敗!"); } }
參考文章 http://www.jcodecraeer.com/a/javascript/2015/0201/2393.html
MVC 中Simditor上傳本地圖片