Ueditor version: 1.4.3
File receive processing is written to the controller and does not use the ashx provided by the editor to receive the upload file
The editor is instantiated because the required editor functions for different pages are not the same, and the configuration parameters are passed in when instantiated:
var editor = new Baidu.editor.ui.Editor ({toolbars: [["Date", "Time", "Horizontal", "anchor", "Spechars", "bloc Kquote "," PageBreak "," bold "," Italic "," Underline "," strikethrough "," ForeColor ", "BackColor", "Justifyleft", "Justifycenter", "Justifyright", "justifyjustify", "directionalityltr", "Directionalityr TL "," Indent "," Removeformat "," Autotypeset "," Formatmatch "," Pasteplain "], [" Customstyle "," paragraph "," rowsp Acingbottom "," Rowspacingtop "," Lineheight "," fontfamily "," FontSize "," Imagenone "," inserttable "," deletetable "," Mergeright "," Mergedown "," Splittorows "], [" Splittocols "," Splittocells "," MergeCells "," Insertcol "," Inser Trow "," Deletecol "," DeleteRow "," insertparagraphbeforetable "," fullscreen "," Source "," undo "," Redo "," Inser Tunorderedlist "," Insertorderedlist "," unlink "," link "," Cleardoc "," SelectAll "," Searchreplace "," separate ", ' Simpleupload '] ], ServerURL: '. /uploadimage '}); Editor.render ("Content");
ServerURL is the upload address, which is the controller action, two colons can not be removed. Give me a chestnut:
nocache=1477646749295. So ServerURL changed to '.. /uploadimage ' is right.
Action Code:
Public ActionResult Uploadimage () {var action = request["Action"]; var json = ""; if (action = = "config") {json =@ "{" "Imageactionname" ":" "Uploadimage" "," "Imagefieldname" ":" "UPF Ile "", "" Imagecompressenable "": "" true "", "" Imagecompressborder "": "," "Imageinsertalign" ":" "None" "," " Imageurlprefix "", "" "," "" Imageallowfiles "": ["". png "", "". jpg "", "". jpeg "", "". gif "", "". bmp ""]} "; } else {var file= request.files["Upfile"]; var relativepath = Appconfig.getappsettingsvalue ("Customizeproductmaskimagerelativepath"); var newfilename = string. Concat (DateTime.Now.ToString ("Yy-mm-dd"), Path.getextension (file. FileName)); var Savepath = Server.MapPath (RelativePath); if (! Directory.Exists (Savepath)) {directory.createdirectory (Savepath); } Relativepath = Path.Combine (RelativePath, NewFileName); Synthetic target file path var srcfilename = Filepath.combinepath (Savepath, NewFileName); Save the picture file. SaveAs (Srcfilename); var tvcmallimageurl = ""; Upload image to extranet server Tvcmallimageurl = ""; JSON = json + "{\" url\ ": \" "+ tvcmallimageurl+" \ ","; JSON = json + "\" state\ ": \" Success\ "}"; } return new Contentresult {contentencoding = Encoding.UTF8, ContentType = "Application/json", Co Ntent = json}; }
Edit receive returns JSON has a pit, if the return is
"{\" imageactionname\ ": \" uploadimage\ ", \" imagefieldname\ ": \" upfile\ ", \" imagecompressenable\ ": \" true\ ", \" Imagecompressborder\ ": 1600,\" imageinsertalign\ ": \" none\ ", \" imageurlprefix\ ": \" \ ", \" imageallowfiles\ ": [\". png\ " , \ ". jpg\", \ ". jpeg\", \ ". gif\", \ ". Bmp\"]} "
Upload Image error: ErrorHandler is not defined (...)
Return to
{"Imageactionname": "Uploadimage", "Imagefieldname": "Upfile", "imagecompressenable": "true", "Imagecompressborder": "Imageinsertalign": "None", "Imageurlprefix": "", "imageallowfiles": [". png", ". jpg", ". jpeg", ". gif", ". bmp"]}
It's normal.
Here are a few gestures that return JSON:
Return Content (JSON, "Application/json", Encoding.UTF8), return JSON (JSON, "Application/json", Encoding.UTF8, Jsonrequestbehavior.allowget); return JavaScript (JSON), return new Jsonresult () {contentencoding = Encoding.UTF8, ContentType = "Application/json", Data = Json,jsonrequestbehavior = Jsonrequestbehavior.allowget};return New Contentresult {contentencoding = Encoding.UTF8, ContentType = "Application/json", Content = json};
1, 3, 5 returns the JSON shown in the browser as
{"Imageactionname": "Uploadimage", "Imagefieldname": "Upfile", "imagecompressenable": "true", "Imagecompressborder": "Imageinsertalign": "None", "Imageurlprefix": "", "imageallowfiles": [". png", ". jpg", ". jpeg", ". gif", ". bmp"]}
The other for
"{\" imageactionname\ ": \" uploadimage\ ", \" imagefieldname\ ": \" upfile\ ", \" imagecompressenable\ ": \" true\ ", \" Imagecompressborder\ ": 1600,\" imageinsertalign\ ": \" none\ ", \" imageurlprefix\ ": \" \ ", \" imageallowfiles\ ": [\". png\ " , \ ". jpg\", \ ". jpeg\", \ ". gif\", \ ". Bmp\"]} "