Reference: https: //www.cnblogs.com/Scholars/p/8968838.html
Download: http://www.wangeditor.com/
Front-end code:
<Script of the type = " text / JavaScript " > // the following two lines of script is pop-up text box var E = window.wangEditor var Editor = new new E ( ' #editor ' ) // upload pictures (for example) editor.customConfig.uploadImgServer = ' /upload.ashx ' // network pictures hide editor.customConfig.showLinkImg = false // the timeout time is changed 3S editor.customConfig.uploadImgTimeout = 1000 * 10 ; document.getElementById ( ' btn1 ').addEventListener('click', function () { // 读取 html alert(editor.txt.html()) }, false) editor.create(); </script> <body> <form id="newspost" method="post" action="newspost" enctype="multipart/form-data"> <input type="hidden" id="content" name="content"/> <div style="padding: 5px 0; color: #ccc"></div> <div id="editor"></div> <br/> </form> <button id="btn1">获取html</button> </body>
Back-end code (typically handler):
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Web; namespace WebApplication1 { /// <summary> /// upload 的摘要说明 /// </summary> public class upload : IHttpHandler { public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/plain"; context.Response.Charset = "utf-8"; var files = context.Request.Files; if (files.Count <= 0) { return; } HttpPostedFile file = files[0]; if (file == null) { context.Response.Write("error|file is null"); return; } else { string Url = "http://192.168.0.20:8099/IMG/"; string path = context.Server.MapPath("/Upader/Img/"); //存储图片的文件夹 if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } string originalFileName = file.FileName; string fileExtension = originalFileName.Substring(originalFileName.LastIndexOf('.'), originalFileName.Length - originalFileName.LastIndexOf('.')); string currentFileName = (new Random()).Next() + fileExtension; // filename not to take Chinese, or an error occurs // generate the file path String imagePath path = + currentFileName; // Save the file file.SaveAs (imagePath); // get the picture url address String imgUrl = " ./Upader/Img / " + currentFileName; String Json = " {\ "Data \": [\ "../../ " + imgUrl.Replace ( @ " \ " , @ " / " ) + " \"], \ "errno \ ": \" 0 \ "} "; //Return to image the url context.Response.Write (Json); return ; } } public BOOL the IsReusable { GET { return to false ; } } } } Usually handler code