. NET MVC uses Ueditor to upload images

Source: Internet
Author: User
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\"]} "
  • 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.