MVC 中Simditor上傳本地圖片

來源:互聯網
上載者:User

標籤: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上傳本地圖片

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.