分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 教程案例

MVC 中Simditor上传本地图片

发布时间:2023-09-06 01:50责任编辑:董明明关键词:MVC

1.引用样式和js文件

<link href="~/Content/scripts/plugins/simditor/css/simditor.css" rel="stylesheet" /><script src="~/Content/scripts/plugins/simditor/js/simditor.js"></script>

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.编写后台处理图片代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
/// <summary>
       /// 上传图片
       /// </summary>
       /// <returns></returns>
       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("上传失败!");
           }
            
       }

MVC 中Simditor上传本地图片

原文地址:https://www.cnblogs.com/moxiaomai/p/8916795.html

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved