kindeditor-4.1.3工具使用技巧:如何在编辑区上传图片并保存绝对路径
MVC项目开中用到了KindEditor图片上传工具,需要在编辑区内上传图片,并将图片的URL保存为符合如下格式地址,如http://192.168.0.111/uploadImg/imgName.jpg.
我是这样处理的:
1、添加引用
<link href="~/Scripts/kindeditor-4.1.3/themes/default/default.css" rel="stylesheet" />
<link href="~/Scripts/kindeditor-4.1.3/plugins/code/prettify.css" rel="stylesheet" />
<script type="text/javascript" src="~/Scripts/kindeditor-4.1.3/kindeditor-all-min.js"></script>
<script type="text/javascript" src="~/Scripts/kindeditor-4.1.3/lang/zh-CN.js"></script>
<script type="text/javascript" src="~/Scripts/kindeditor-4.1.3/plugins/code/prettify.js"></script>
2、初始化
var editor1;
KindEditor.ready(function (K) {
editor1 = K.create('#txtContent', {
uploadJson: '@Url.Content("~/Scripts/kindeditor-4.1.3/asp.net/upload_json.ashx")',
fileManagerJson: '@Url.Content("~/Scripts/kindeditor-4.1.3/asp.net/file_manager_json.ashx")',
allowFileManager: true,
formatUploadUrl: false,
items: ['source', '|', 'undo', 'redo', '|', 'preview', 'print', 'template', 'code', 'cut', 'copy', 'paste',
'plainpaste', 'wordpaste', '|', 'justifyleft', 'justifycenter', 'justifyright',
'justifyfull', 'insertorderedlist', 'insertunorderedlist', 'indent', 'outdent', 'subscript',
'superscript', 'clearhtml', 'quickformat', 'selectall', '|', 'fullscreen', '/',
'formatblock', 'fontname', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold',
'italic', 'underline', 'strikethrough', 'lineheight', 'removeformat', '|', 'image',
'pagebreak', 'anchor', '|', 'link', 'unlink'
],
themeType: 'simple'
});
});
这里要注意的是,要想得到绝对地址,一定要设置这个属性
formatUploadUrl: false
HTML代码里增加占位元素
<input type="text" id="txtContent" name="UserIntroduce" style="width: 670px; height: 200px; " />
“UserIntroduce”为属性名,这个要给对了,不然拿不到值。
这样,在提交表单时就可以获取到里面的内容了。
3、上传图片时点确定上传与保存图片
我用的是工具包自带的上传功能文件名:upload_json.ashx
它提供判断、保存与返回路径,功能已经很全了。
我们的绝地址就是在这个文件里创建的。
一顿拼呀...
Uri uri = HttpContext.Current.Request.Url;
string url = "http://" + uri.Host + ":" + uri.Port.ToString() + "/Upload/"+path+"/" + fileName;
这个url就是我们要保存到数据库中的啦。
4、提交表单
function SaveForm() {
editor1.sync();
$('#fm').form('submit', {
url: '/Member/AddMember',
type: 'post',
onSubmit: function () {
return $(this).form('validate');
},
success: function (result) {
var result = eval('(' + result + ')');
if (result.flag != "OK") {
$.messager.show({
title: 'Error',
msg: "保存失败。"
});
}
else {
$.messager.show({
title: '提示',
msg: "操作成功"
});
window.location.href = "/Member/Index";
}
}
});
}
注意,提交时一定要调一下editor1.sync(),不然后台拿不到值。
5、后台接收与保存
就是用相应对象接收表单数据就可以了,不说了。
kindeditor-4.1.3工具使用技巧:如何在编辑区上传图片并保存绝对路径的更多相关文章
- Windows SharePoint Services 3.0编码开发工具和技巧(Part 1 of 2)
转:http://blog.csdn.net/mattwin/article/details/2074984 WSSv3 Technical Articles_Windows SharePoint S ...
- phpstorm 工具使用技巧(持续补充中。。。)
phpstorm 工具使用技巧(持续补充中...) 一.phpstorm大小写切换 1.选择要转换的目标字符串: //普通商家,普通折扣默认值'COMMON_DISCOUNT'=>10.00, ...
- Idea工具常用技巧总结
转自:https://www.jianshu.com/p/131c2deb3ecf Idea常用技巧总结 1.无处不在的跳转 注:这里的快捷键是自己定义的,并非大家的都一样,可以通过findActio ...
- ecshop编辑器FCKeditor修改成KindEditor编辑批量上传图片
ecshop一直使用的编辑器是fck,这个不用多说,相信很多朋友用的很悲剧吧,特别是图片不能批量上传图片. 今天小编就分享一下怎么换掉fck,放上实用的kindeditor,最新ecshop版 ...
- 易维清使用技巧:CHM编辑利器
易维清源代码生成软件不但是一款专业的管理信息系统源代码生成器,其附带的编辑帮助信息功能更是CHM编辑利器.而且,免费试用版中的这个功能完全没有削减的哦,不花钱就可以帮你轻松编辑生成完美的CHM,官方下 ...
- 工欲善其事,必先利其器 之 WPF篇: 随着开发轨迹来看高效WPF开发的工具和技巧
之前一篇<工欲善其事,必先利其器.VS2013全攻略(安装,技巧,快捷键,插件)!> 看到很多朋友回复和支持,非常感谢,尤其是一些拍砖的喷油,感谢你们的批评,受益良多. 我第一份工作便是W ...
- 前端调试效率低?试试这10个“Chrome开发者工具”使用技巧
摘要:今天给大家分享一些使用“Chrome开发者工具”的小技巧.包括调试,优化页面渲染速度等.希望能提升Web开发人员的工作效率. 今天给大家分享一些使用“Chrome开发者工具”的小技巧.包括调试, ...
- linux-exp 工具+小技巧
# 工具篇 # pwntools ,gdb-peda ROPgadget-tool . EDB ## pwntools获取.安装和文档帮助 ## - pwntools: github可以搜索到 htt ...
- Chrome 开发者工具使用技巧
最近我花了较多的时间使用 Chrome 的开发者工具.我发现了很多之前没用过的好功能 (或还不是特别需要用到的功能,例如 blackboxing 和 asynchronous stacktraces) ...
随机推荐
- CSS 常用基本功能整理
1.文字访问特权 点击前.点击时.点击后.下划线.跳转. <!DOCTYPE html> <html> <head> <meta charset=" ...
- Javascript模块化编程(一):模块的写法
Javascript模块化编程(一):模块的写法 作者: 阮一峰 原文链接:http://www.ruanyifeng.com/blog/2012/10/javascript_module.html ...
- 面向对象Part1对象的创建和Static!
面向对象的特征: 1)封装 2)继承 3)多台 4)抽象 创建的是什么类型的对象 变量的声明就是什么类型. class Servant{ void xxx (){} } Servant s1 = ne ...
- 微软往年校招招面试题AC全解。
因为4月初要参加微软的online.所以今天把微软的面试题拿出来做了,自己解答了题目.下面附上我的解答代码. -----------16年9月校招: 第一道题:Farthest Point(最远的整 ...
- yum 保存下载包
--- 1 --- $ sudo yum install yum-plugin-downloadonly $ sudo yum install --downloadonly --downloaddir ...
- Install PIL with Jpeg support on Raspbian Jessie
参考: https://www.raspberrypi.org/forums/viewtopic.php?f=91&t=79379 在 树莓派(Raspbian Jessie) 上安装djan ...
- ACM/ICPC 之 靠墙走-DFS+BFS(POJ3083)
//POJ3083 //DFS求靠左墙(右墙)走的路径长+BFS求最短路 //Time:0Ms Memory:716K #include<iostream> #include<cst ...
- c#线程间操作无效: 从不是创建控件“textBox1”的线程访问它
线程开始前: Control.CheckForIllegalCrossThreadCalls = false;
- Swift - UIView,UItableView,Cell设置边框方法
// 设置边框的宽度 cell.layer.borderWidth = 1 // 设置边框的颜色 cell.layer.borderColor = UIColor.blackColor().CGCol ...
- jsonp是什么【转载自JavaScript微信公众号】
转自 http://mp.weixin.qq.com/s/xNnKAeLv6sO0T-IvP2AUlQ JavaScript微信公众号 一.JSONP的诞生 首先,因为ajax无法跨 ...