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工具使用技巧:如何在编辑区上传图片并保存绝对路径的更多相关文章

  1. Windows SharePoint Services 3.0编码开发工具和技巧(Part 1 of 2)

    转:http://blog.csdn.net/mattwin/article/details/2074984 WSSv3 Technical Articles_Windows SharePoint S ...

  2. phpstorm 工具使用技巧(持续补充中。。。)

    phpstorm 工具使用技巧(持续补充中...) 一.phpstorm大小写切换 1.选择要转换的目标字符串: //普通商家,普通折扣默认值'COMMON_DISCOUNT'=>10.00, ...

  3. Idea工具常用技巧总结

    转自:https://www.jianshu.com/p/131c2deb3ecf Idea常用技巧总结 1.无处不在的跳转 注:这里的快捷键是自己定义的,并非大家的都一样,可以通过findActio ...

  4. ecshop编辑器FCKeditor修改成KindEditor编辑批量上传图片

    ecshop一直使用的编辑器是fck,这个不用多说,相信很多朋友用的很悲剧吧,特别是图片不能批量上传图片.     今天小编就分享一下怎么换掉fck,放上实用的kindeditor,最新ecshop版 ...

  5. 易维清使用技巧:CHM编辑利器

    易维清源代码生成软件不但是一款专业的管理信息系统源代码生成器,其附带的编辑帮助信息功能更是CHM编辑利器.而且,免费试用版中的这个功能完全没有削减的哦,不花钱就可以帮你轻松编辑生成完美的CHM,官方下 ...

  6. 工欲善其事,必先利其器 之 WPF篇: 随着开发轨迹来看高效WPF开发的工具和技巧

    之前一篇<工欲善其事,必先利其器.VS2013全攻略(安装,技巧,快捷键,插件)!> 看到很多朋友回复和支持,非常感谢,尤其是一些拍砖的喷油,感谢你们的批评,受益良多. 我第一份工作便是W ...

  7. 前端调试效率低?试试这10个“Chrome开发者工具”使用技巧

    摘要:今天给大家分享一些使用“Chrome开发者工具”的小技巧.包括调试,优化页面渲染速度等.希望能提升Web开发人员的工作效率. 今天给大家分享一些使用“Chrome开发者工具”的小技巧.包括调试, ...

  8. linux-exp 工具+小技巧

    # 工具篇 # pwntools ,gdb-peda ROPgadget-tool . EDB ## pwntools获取.安装和文档帮助 ## - pwntools: github可以搜索到 htt ...

  9. Chrome 开发者工具使用技巧

    最近我花了较多的时间使用 Chrome 的开发者工具.我发现了很多之前没用过的好功能 (或还不是特别需要用到的功能,例如 blackboxing 和 asynchronous stacktraces) ...

随机推荐

  1. maven实战(02)_坐标详解

    (一)  何为mave坐标 maven的世界中拥有数量非常巨大的构件,也就是平时用的一些jar,war等文件. maven定义了这样一组规则: 世界上任何一个构件都可以使用Maven坐标唯一标志,ma ...

  2. setprecision **fixed

    #include <iostream> #include <iomanip> using namespace std; int main( void ) { const dou ...

  3. CDR VBA鼠标选择

    Dim x As Double, y As Double, Shift As Long, b As Boolean, doc As Document Dim sel1 As Shape, sel2 A ...

  4. input表单手机号、身份证号验证

    <form action="" method="post" onsubmit="return checkForm(this)"> ...

  5. history命令详解

    Linux下history命令用法 ^_^在项目中希望调用history命令来获取用户的历史记录,方便分析,可是我们平时所见到的history结果是下面这样: # history | head -10 ...

  6. Spring学习(一)

    1.既然是学习Spring,我们首先要搞清楚Spring是什么? Spring是分层的.JavaSE/EE一站式的.轻量级的开源框架. 2.Spring的核心 百度百科:Spring是基于IOC和AO ...

  7. IO边读边写

      using (FileStream fs = new FileStream(@"C:\Users\Desktop\lijia1.txt",FileMode.Open))     ...

  8. Redis

    1. sds类型 sds为一种抽象数据结构 typedef char *sds;struct sdshdr { // buf 已占用长度int len; // buf 剩余可用长度int free;  ...

  9. poi导出excel

    Java使用poi组件导出excel报表,能导出excel报表的还可以使用jxl组件,但jxl想对于poi功能有限,jxl应该不能载excel插入浮动层图片,poi能很好的实现输出excel各种功能, ...

  10. Xcode8更新约束

    Xcode升级之后就会发现约束设置好,想更新一下约束,看看约束是不是刚刚好,习惯性的去点右下角的更新约束的结果却发现没有更新约束的这一项了,好尴尬. 后来发现原来在Xcode8的约束更新换了一个地方, ...