Simditor uploading local images in MVC

Source: Internet
Author: User

1. Referencing styles and JS files

<link href= "~/content/scripts/plugins/simditor/css/simditor.css" rel= "stylesheet"/><script src= "~/ Content/scripts/plugins/simditor/js/simditor.js "></script>

2. Initialize Simditor

var editor = null;    $ (function () {        //can refer to http://www.jcodecraeer.com/a/javascript/2015/0201/2393.html        editor = new Simditor ({            textarea: $ (' #NewsContent '),            placeholder: ' Enter the announcement here ... ',            toolbar: [' title ', ' Bold ', ' Italic ', ' Underline ', ' strikethrough ', ' color ', ' | ', ' ol ', ' ul ', ' blockquote ', ' Code ', ' table ', ' | ', ' link ', ' image ', ' hr ', ' | ', ' in Dent ', ' outdent '],            upload: {                url: '/publicinfomanage/notice/savepic ',//File Upload interface address                params:null,//key-value pair, Specify the additional parameters of the file upload interface, when uploading with the file                filekey: ' Filedatafilename ',//server side get File data parameter name                Connectioncount:3,                Leaveconfirm: ' Uploading file '}        })    

Upload settings will appear in the options

Before implementing the function, you need to modify the referenced JS file, use the view browser's audit element function to view, found the input button does not have the Name property

3. Open the Simditor.js file to search the Accept property, then add "name=" FileData "properties, a total of two need to add, as

4. Write the background processing picture code

123456789101112131415161718192021222324 /// <summary>       /// 上传图片       /// </summary>       /// <returns></returns>       public ActionResult SavePic()       {           HttpPostedFileBase file = Request.Files["fileDataFileName"];           if(file != null)           {               stringstrPath = HttpContext.Server.MapPath("/Content/Upload/");               if(!Directory.Exists(strPath))               {                   Directory.CreateDirectory(strPath);               }               stringfilePath = Path.Combine(strPath, Path.GetFileName(file.FileName));               file.SaveAs(filePath);               returnSuccess("上传成功!");           }           else           {               returnSuccess("上传失败!");           }                  }

Simditor uploading local images in MVC

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.