Summernote Upload Picture save path (C #)

Source: Internet
Author: User

1. Write a div,id for content

1 <  ID= "Content"  class= "summernotecontent">23  </div>

2. Make it a rich text box and pass it to the background

1$ ("#Content"). Summernote ({2height:200,3Lang: ' ZH-CN ',4MinHeight:NULL,5MaxHeight:NULL,6Airpopover: [[' Color ', [' color ']], [' Font ', [' bold ', ' underline ', ' clear ']], [' Para ', [' ul ', ' paragraph ']], [' Table ', [' t Able '], [' Insert ', [' link ', ' picture ']]],7OnChange:function(e) {8$ ("input[id=content]"). Val ($ ('. Summernotecontent ')). code ());9             },TenOnChange:function(e) { One$ ("input[id=news_content]"). Val ($ ('. Summernotecontent ')). code ()); A             }, -Onblurfunction(e) { -$ ("input[id=news_content]"). Val ($ ('. Summernotecontent ')). code ()); the             }, -Onimageupload:function(Files, editor, $editable) { -SendFile (files[0]); -             }, +         }); -         functionsendFile (file) { +data =NewFormData (); AData.append ("File", file); at $.ajax ({ - Data:data, -Type: "POST", -URL: "/news/upload",//image upload URL, return the image after uploading the path, HTTP format -ContentType:false, -Cachefalse, inProcessData:false, -Successfunction(data) { to                     //data is the value of the returned Hash,key, key is the defined filename + alert (data); -                     //Put the picture in the edit box. Editor.insertimage is a parameter that writes dead.  The following HTTP is the image resource path on the web.  the                     //A lot of online is this step error.  *$ (' #Content '). Summernote (' Editor.insertimage ', "http://res.cloudinary.com/demo/image/upload/butterfly.jpg")); $                     Panax Notoginseng                 }, -Errorfunction () { the$ (". Note-alarm"). html ("Upload failed"); +SetTimeout (function() {$ (". Note-alarm"). Remove ();}, 3000); A                 } the             }); +}

3. Receive data in the background and save

1  Publicactionresult Upload ()2         {3HttpPostedFileBase Filedata = request.files["file"];4             //If the file is not uploaded5             if(Filedata = =NULL||string. IsNullOrEmpty (filedata.filename) | | Filedata.contentlength = =0)6             {7                 return  This. Httpnotfound ();8             }9             //save to the ~/img folder, the name does not changeTen             //string filename = System.IO.Path.GetFileName (filedata.filename); One             stringfilename = getimagename () +System.IO.Path.GetExtension (filedata.filename); A             stringVirtualPath =string. Format ("~/image/newsimg/{0}", filename); -             //The file system cannot use the virtual path -             stringPath = This. Server.MapPath (virtualpath); the filedata.saveas (path); -             returnJson ("/image/newsimg/"+filename); -}

Reference Blog: http://blog.csdn.net/shenyingkui/article/details/45692167

Summernote Upload Picture save path (C #)

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.