栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > asp

一步步教你在Asp.net Mvc中使用UEditor编辑器

asp 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

一步步教你在Asp.net Mvc中使用UEditor编辑器

最近在配置.net mvc4项目使用ueditor编辑器,在配置过程中遇见了好几个问题,以此来记录解决办法。

首先去这里下载

然后重名一下下载的文件夹为ueditor(想自己起名字也可以,不过配置文件就要改成一样的了,这里为了避免麻烦,就跟配置文件里的名字保持一致了)

然后根据自己需要放到项目中,我是这么放的

上面建的文件夹也是跟配置文件保持一致,并不是非要照着这么做,这里只是跟配置文件保持一致,可以根据自己需要修改配置文件,自己想怎么建都行,看看配置文件就明白了

config.json


{
 
 "imageActionName": "uploadimage", 
 "imageFieldName": "upfile", 
 "imageMaxSize": 2048000, 
 "imageAllowFiles": [".png", ".jpg", ".jpeg", ".gif", ".bmp"], 
 "imageCompressEnable": true, 
 "imageCompressBorder": 1600, 
 "imageInsertAlign": "none", 
 "imageUrlPrefix": "scripts/ueditor/net/", 
 "imagePathFormat": "upload/image/{yyyy}{mm}{dd}/{time}{rand:6}", 
    
    
    
    
    
    
    
    
    
    
    
    

 
 "scrawlActionName": "uploadscrawl", 
 "scrawlFieldName": "upfile", 
 "scrawlPathFormat": "upload/image/{yyyy}{mm}{dd}/{time}{rand:6}", 
 "scrawlMaxSize": 2048000, 
 "scrawlUrlPrefix": "/ueditor/net/", 
 "scrawlInsertAlign": "none",

 
 "snapscreenActionName": "uploadimage", 
 "snapscreenPathFormat": "upload/image/{yyyy}{mm}{dd}/{time}{rand:6}", 
 "snapscreenUrlPrefix": "/ueditor/net/", 
 "snapscreenInsertAlign": "none", 

 
 "catcherLocalDomain": ["127.0.0.1", "localhost", "img.baidu.com"],
 "catcherActionName": "catchimage", 
 "catcherFieldName": "source", 
 "catcherPathFormat": "upload/image/{yyyy}{mm}{dd}/{time}{rand:6}", 
 "catcherUrlPrefix": "/ueditor/net/", 
 "catcherMaxSize": 2048000, 
 "catcherAllowFiles": [".png", ".jpg", ".jpeg", ".gif", ".bmp"], 

 
 "videoActionName": "uploadvideo", 
 "videoFieldName": "upfile", 
 "videoPathFormat": "upload/video/{yyyy}{mm}{dd}/{time}{rand:6}", 
 "videoUrlPrefix": "/ueditor/net/", 
 "videoMaxSize": 102400000, 
 "videoAllowFiles": [
 ".flv", ".swf", ".mkv", ".avi", ".rm", ".rmvb", ".mpeg", ".mpg",
 ".ogg", ".ogv", ".mov", ".wmv", ".mp4", ".webm", ".mp3", ".wav", ".mid"], 

 
 "fileActionName": "uploadfile", 
 "fileFieldName": "upfile", 
 "filePathFormat": "upload/file/{yyyy}{mm}{dd}/{time}{rand:6}", 
 "fileUrlPrefix": "/ueditor/net/", 
 "fileMaxSize": 51200000, 
 "fileAllowFiles": [
 ".png", ".jpg", ".jpeg", ".gif", ".bmp",
 ".flv", ".swf", ".mkv", ".avi", ".rm", ".rmvb", ".mpeg", ".mpg",
 ".ogg", ".ogv", ".mov", ".wmv", ".mp4", ".webm", ".mp3", ".wav", ".mid",
 ".rar", ".zip", ".tar", ".gz", ".7z", ".bz2", ".cab", ".iso",
 ".doc", ".docx", ".xls", ".xlsx", ".ppt", ".pptx", ".pdf", ".txt", ".md", ".xml"
 ], 

 
 "imageManagerActionName": "listimage", 
 "imageManagerListPath": "upload/image", 
 "imageManagerListSize": 20, 
 "imageManagerUrlPrefix": "/ueditor/net/", 
 "imageManagerInsertAlign": "none", 
 "imageManagerAllowFiles": [".png", ".jpg", ".jpeg", ".gif", ".bmp"], 

 
 "fileManagerActionName": "listfile", 
 "fileManagerListPath": "upload/file", 
 "fileManagerUrlPrefix": "/ueditor/net/", 
 "fileManagerListSize": 20, 
 "fileManagerAllowFiles": [
 ".png", ".jpg", ".jpeg", ".gif", ".bmp",
 ".flv", ".swf", ".mkv", ".avi", ".rm", ".rmvb", ".mpeg", ".mpg",
 ".ogg", ".ogv", ".mov", ".wmv", ".mp4", ".webm", ".mp3", ".wav", ".mid",
 ".rar", ".zip", ".tar", ".gz", ".7z", ".bz2", ".cab", ".iso",
 ".doc", ".docx", ".xls", ".xlsx", ".ppt", ".pptx", ".pdf", ".txt", ".md", ".xml"
 ] 

}

如果要自定义,下面的配置项必须改

"imageUrlPrefix": "scripts/ueditor/net/", 
"imagePathFormat": "upload/image/{yyyy}{mm}{dd}/{time}{rand:6}", 
 "fileUrlPrefix": "/ueditor/net/", 

配置文件 ueditor.config.js 下面的

window.UEDITOR_HOME_URL 可以不指定也可以指定,不指定的话,那就在MVC视图里面指定,如下所示

......

......

总之就是下面几个步骤

1.下载UEditor插件,把文件夹放在项目根目录下,改名,省事的话就跟配置文件保持一致。

2.建立一个Controller, Action方法加上 [ValidateInput(false)]

 public class UEditorController : Controller
 {
 [ValidateInput(false)]
 // GET: UEditor
 public ActionResult Index(FormCollection fc)
 {
 }
 }

3.建立视图,视图名称跟Controller的Action方法名称一致






@{
 ViewBag.Title = "UEditorDemo";
}


@using (Html.BeginForm("Index", "UEditor", FormMethod.Post))
{
 
 
}

4.修改Controller如下

 public ActionResult Index(FormCollection fc)
 {
  var content = fc["editor"];
  return View();
 }

5.首页弹出UEditor的页面用来测试,修改App_Start文件夹下的RouteConfig

 public class RouteConfig
 {
 public static void RegisterRoutes(RouteCollection routes)
 {
  routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

  routes.MapRoute(
  name: "Default",
  url: "{controller}/{action}/{id}",
  //defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
  defaults: new { controller = "UEditor", action = "Index", id = UrlParameter.Optional }
  );
 }
 }

6.默认我们并不需要UEditor工具栏上的所有按钮,需要屏蔽一些,这个时候需要修改ueditor.config.js

 , toolbars: [[
  //'fullscreen', 'source', '|', 'undo', 'redo', '|',
  //'bold', 'italic', 'underline', 'fontborder', 'strikethrough', 'superscript', 'subscript', 'removeformat', 'formatmatch', 'autotypeset', 'blockquote', 'pasteplain', '|', 'forecolor', 'backcolor', 'insertorderedlist', 'insertunorderedlist', 'selectall', 'cleardoc', '|',
  //'rowspacingtop', 'rowspacingbottom', 'lineheight', '|',
  //'customstyle', 'paragraph', 'fontfamily', 'fontsize', '|',
  //'directionalityltr', 'directionalityrtl', 'indent', '|',
  //'justifyleft', 'justifycenter', 'justifyright', 'justifyjustify', '|', 'touppercase', 'tolowercase', '|',
  //'link', 'unlink', 'anchor', '|', 'imagenone', 'imageleft', 'imageright', 'imagecenter', '|',
  //'simpleupload', 'insertimage', 'emotion', 'scrawl', 'insertvideo', 'music', 'attachment', 'map', 'gmap', 'insertframe', 'insertcode', 'webapp', 'pagebreak', 'template', 'background', '|',
  //'horizontal', 'date', 'time', 'spechars', 'snapscreen', 'wordimage', '|',
  //'inserttable', 'deletetable', 'insertparagraphbeforetable', 'insertrow', 'deleterow', 'insertcol', 'deletecol', 'mergecells', 'mergeright', 'mergedown', 'splittocells', 'splittorows', 'splittocols', 'charts', '|',
  //'print', 'preview', 'searchreplace', 'drafts', 'help'

  'undo', 'redo', '|',
  'bold', 'forecolor', 'removeformat', 'autotypeset', 'pasteplain', '|', '|',
  'justifyleft', 'justifycenter', 'justifyright', 'justifyjustify', '|',
  'link', 'unlink', '|',
  'simpleupload', 'insertimage', '|',
  'wordimage', '|',
  'inserttable', 'insertrow', 'deleterow', 'insertcol', 'deletecol', 'mergecells', 'splittocells'
 ]]

如上,我把原始的工具栏配置项注释掉了,运行一下出现如下效果


已经少了不少平常用不上的按钮,好了大功告成~!

总结

以上就是这篇文章的全部内容了,希望本文的内容对大家学习或者使用Asp.net能带来一定的帮助,如果有疑问大家可以留言交流。

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/55873.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号