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 #)