博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
MVC 中Simditor上传本地图片
阅读量:4641 次
发布时间:2019-06-09

本文共 1702 字,大约阅读时间需要 5 分钟。

1.引用样式和js文件

 

2.初始化Simditor

var editor = null;    $(function () {        //可以参考 http://www.jcodecraeer.com/a/javascript/2015/0201/2393.html        editor = new Simditor({            textarea: $('#NewsContent'),            placeholder: '这里输入公告内容...',            toolbar: ['title', 'bold', 'italic', 'underline', 'strikethrough', 'color', '|', 'ol', 'ul', 'blockquote', 'code', 'table', '|', 'link', 'image', 'hr', '|', 'indent', 'outdent'],            upload: {                url: '/PublicInfoManage/Notice/SavePic', //文件上传的接口地址                params: null, //键值对,指定文件上传接口的额外参数,上传的时候随文件一起提交                fileKey: 'fileDataFileName', //服务器端获取文件数据的参数名                connectionCount: 3,                leaveConfirm: '正在上传文件'            }        });    })

 

upload设置好就会出现下图中的选项

实现功能之前需要修改一下引用的js文件,使用查看浏览器的审核元素功能查看,发现input按钮么有name属性

3.打开Simditor.js文件搜索accept属性,然后添加“name=“fileData”属性,共有两处需要添加,如下图

 

4.编写后台处理图片代码

///        /// 上传图片       ///        /// 
public ActionResult SavePic() { HttpPostedFileBase file = Request.Files["fileDataFileName"]; if (file != null) { string strPath = HttpContext.Server.MapPath("/Content/Upload/"); if (!Directory.Exists(strPath)) { Directory.CreateDirectory(strPath); } string filePath = Path.Combine(strPath, Path.GetFileName(file.FileName)); file.SaveAs(filePath); return Success("上传成功!"); } else { return Success("上传失败!"); } }

 

 

 

来源:http://www.cnblogs.com/ZJ199012/p/6134782.html

 

转载于:https://www.cnblogs.com/youmingkuang/p/6548054.html

你可能感兴趣的文章
CSE 3100 Systems Programming
查看>>
IntelliJ IDEA 的Project structure说明
查看>>
Java Security(JCE基本概念)
查看>>
Linux Supervisor的安装与使用入门
查看>>
创建 PSO
查看>>
JasperReport报表设计4
查看>>
项目活动定义 概述
查看>>
团队冲刺04
查看>>
我的Python分析成长之路8
查看>>
泛型在三层中的应用
查看>>
SharePoint2010 -- 管理配置文件同步
查看>>
.Net MVC3中取得当前区域的名字(Area name)
查看>>
获得屏幕像素以及像素密度
查看>>
int与string转换
查看>>
adb命令 判断锁屏
查看>>
推荐一个MacOS苹果电脑系统解压缩软件
查看>>
1035等差数列末项计算
查看>>
CDMA鉴权
查看>>
ASP.NET MVC Identity 兩個多個連接字符串問題解決一例
查看>>
过滤器与拦截器区别
查看>>