easyuiForm提交:

前台代码:

<form id="importFileForm" method="post" enctype="multipart/form-data" style="display:">
<table style="margin:5px;height:70px;">
<tr>
<td></td>
<td width="5px;"></td>
<td><input class="easyui-filebox" id="fileImport" data-options="buttonText:'选择',prompt:'请选择文件...'" name="fileImport" style="width:260px;">
</td>
<td><a id="uploadFile" class="easyui-linkbutton" data-options="iconCls:'icon-ok'" href="javascript:void(0)">上传</a></td>
</tr>
<tr>
<td colspan="4">
<label id="uploadInfo" />
</td>
</tr>
</table>
</form>
<script>
//导入文件
$("#uploadFile").click(function () {
var formData = new FormData($("#importFileForm")[0]);
//调用apicontroller后台action方法,将form数据传递给后台处理。contentType必须设置为false,否则chrome和firefox不兼容
$.ajax({
url: "http://localhost:12745/api/easyuiUpload/PostExcelData",
type: 'POST',
data: formData,
async: false,
cache: false,
contentType: false,
processData: false,
success: function (returnInfo) {
//上传成功后将控件内容清空,并显示上传成功信息
document.getElementById('fileImport').value = null;
document.getElementById('uploadInfo').innerHTML = "<span style='color:Red'>" + returnInfo + "</span>";
},
error: function (returnInfo) {
//上传失败时显示上传失败信息
document.getElementById('uploadInfo').innerHTML = "<span style='color:Red'>" + returnInfo + "</span>";
}
}); })
</script>

 后台代码:

[HttpPost]
public string PostExcelData()
{
string info = string.Empty;
try
{
//获取客户端上传的文件集合
HttpFileCollection files = System.Web.HttpContext.Current.Request.Files;
//判断是否存在文件
if (files.Count > 0)
{
//获取文件集合中的第一个文件(每次只上传一个文件)
HttpPostedFile file = files[0];
//定义文件存放的目标路径
string targetDir = System.Web.HttpContext.Current.Server.MapPath("~/FileUpLoad/Product");
//创建目标路径
if (!Directory.Exists(targetDir))
{
Directory.CreateDirectory(targetDir);
}
//ZFiles.CreateDirectory(targetDir);
//组合成文件的完整路径
string path = System.IO.Path.Combine(targetDir, System.IO.Path.GetFileName(file.FileName));
//保存上传的文件到指定路径中
file.SaveAs(path);
info = "上传成功";
}
else
{
info = "上传失败";
}
}
catch
{
info = "上传失败";
}
return info;
}

  

 easyui另类Form提交(前台页不需要form表单):

前台代码:

<script type="text/javascript">

        $.support.cors = true;
var ApiUrl = "http://localhost:12745/";
$(function () {
$("#upload").click(function () {
$("#imgWait").show();
var formData = new FormData();
formData.append("myfile", $("#file1").next().find('input[id^="filebox_file_id_"]')[0].files[0]);
formData.append("myfile2", $("#file2").next().find('input[id^="filebox_file_id_"]')[0].files[0]);
$.ajax({
url: ApiUrl + "api/FileManage/UploadFile",
type: "POST",
data: formData,
/**
*必须false才会自动加上正确的Content-Type
*/
contentType: false,
/**
* 必须false才会避开jQuery对 formdata 的默认处理
* XMLHttpRequest会对 formdata 进行正确的处理
*/
processData: false,
success: function (data) {
if (data.status == "true") {
alert("上传成功!");
}
if (data.status == "error") {
alert(data.msg);
}
$("#imgWait").hide();
},
error: function () {
alert("上传失败!");
$("#imgWait").hide();
}
});
});
});
</script>
</head>
<body>
<!--选择文件:<input type="file" id="file1" /><br />-->
<input class="easyui-filebox" id="file1" data-options="prompt:'Choose another file...'" style="width:150px">
<input class="easyui-filebox" id="file2" data-options="prompt:'Choose another file...'" style="width:150px">
<input type="button" id="upload" value="上传" />
<img src="wait.gif" style="display:none" id="imgWait" />
</body>

  后台代码:

[HttpPost]
public HttpResponseMessage UploadFile()
{
HttpResponseMessage result = null;
var httpRequest = System.Web.HttpContext.Current.Request;
if (httpRequest.Files.Count > 0)
{
try
{
string url = string.Empty;
foreach (string file in httpRequest.Files)
{ var postedFile = httpRequest.Files[file];
var filePath = System.Web.HttpContext.Current.Server.MapPath("~/Files/");
if (!Directory.Exists(filePath))
{
Directory.CreateDirectory(filePath);
}
postedFile.SaveAs(filePath + postedFile.FileName);
url += "Files/" + postedFile.FileName + ",";
} result = Request.CreateResponse(HttpStatusCode.OK, url.Substring(0, url.Length - 1)); }
catch (Exception ex)
{
result = Request.CreateResponse(HttpStatusCode.OK, "error:" + ex.Message);
} }
else
{
result = Request.CreateResponse(HttpStatusCode.OK, "0");
}
return result;
}

  

easyui上次图片的更多相关文章

  1. EasyUI实现图片的上传后与其他文本框的提交以及DataGrid中图片的展示

    图片即文件,在jsp中文件上传很简单,一个type为file的input,一个form指定enctype为multipart/form-data,通过post提交到后台利用apache的commons ...

  2. easyui多图片上传+预览切换+支持IE8

    引入css和js: <link href="${pageContext.request.contextPath}/plugin/dialog/dialog.css" rel= ...

  3. asp:FileUpload 上次图片

    <asp:FileUpload ID="FileUpload附件" runat="server" Width="200px" /> ...

  4. C#--图片上传(PC端和APP)保存及 跨域上传说明

    手动跨域操作文件 补录:跨域访问文件夹文件是一种常见的需求,下面主要介绍的的通过代码使用具有权限账号的人来达到跨域操作文件的能力. 现在补充一下普通的一些需求场景,今天就遇到了一种需要经常需要登录远程 ...

  5. SSM后台管理系统(Spring SpringMVC Mybatis Mysql EasyUI)

    非常简单的一个后台管理系统,功能不多,框架也不复杂, 源码下载(附数据库)-ssm后台管理系统框架(Spring mvc + mybatis + mysql + easyui ) 实例图片

  6. EasyUI之Layout布局和Tabs页签的使用

    1.JQuery EasyUI之LayOut布局 EasyUI是一款基于JQuery开发的前端框架,它集成很多漂亮的样式和相应的功能,大大方便了我们对前端开发的难度.对于web项目而言,主页面的一定是 ...

  7. php,session验证码不一致慢半拍

    这种问题遇到过一次,后来忘了怎么解决了,所以做下笔记 输出的$_SESSION['code']之所以比图片慢了‘一帧’,这也纯属正常情况因为输出的图片是一个连接一次调用,而echo $_SESSION ...

  8. node.js之十大Web框架

    之前接触过Node.js是因为好奇大前端越来越能干了,连我后台的饭碗都要抢了,太嚣张了,于是我想打压打压它,然后就这样接触它了.再到后来是因为Settings-Sync插件二次开发,我需要用node. ...

  9. Uncaught InvalidStateError: Failed to set the 'value' property on 'HTMLInputElement': This input element accepts a filename, which may only be programmatically set to the empty string.

    使用 HTML5 的图片上传api的时候报如下错误: Uncaught InvalidStateError: Failed to set the 'value' property on 'HTMLIn ...

随机推荐

  1. Android API之android.os.AsyncTask

    android.os.AsyncTask<Params, Progress, Result> AsyncTask enables proper and easy use of the UI ...

  2. 安装Ubuntu 13.04后要做的六件事

    2013-05-07 09:23    最新版本的Ubuntu已经新鲜出炉:Ubuntu 13.04,代号为Raring Ringtail.作为幕后开发Ubuntu Linux的公司,Canonica ...

  3. 超级干货,python常用函数大总结

    我们在学习python的时候,接触最多的往往则是那些函数,对于python函数,在这里为大家总结归纳了这些,如果有缺漏,还请及时留言指正哦! 话不多说,干货来袭! 1.常用内置函数:(不用import ...

  4. unity, destroy gameObject & destroy all children

    一,destroy gameObject 删除名为xxx的gameObject 错误方法1: Destroy(xxx); 以上方法之所以错误,是因为Destroy在下一帧才生效,而在本帧之内xxx还存 ...

  5. MySql(三):MyISAM和InnoDB区别详解

    MyISAM是MySQL的默认数据库引擎(5.5版之前),由早期的ISAM(Indexed Sequential Access Method:有索引的顺序访问方法)所改良.虽然性能极佳,但却有一个缺点 ...

  6. 关于Unity层级面板的自动初始化

    Transform[],GameObject[]这些class类型,Unity会进行自动初始化. 但[ExecuteInEditMode]在编辑模式下执行的时候,会发现初始化其实也是有顺序的,并且在U ...

  7. 基于Vivado的嵌入式开发 ——PS+PL实践

    基于Vivado的嵌入式开发 ——PS走起 硬件平台:ZedBoard 开发工具:Vivado 2014.2 1.规划 废话不多说,依然是流水灯,这次是采用PS+PL实现. 功能依旧简单,目标是为了学 ...

  8. EF操作VS中

    1.安装mysql server 2.安装MySql的VS插件(版本请下载最新版,百度自己搜索,这个不用多说)mysql-for-visualstudio-1.2.3.msi 3.安装用于.net连接 ...

  9. jenkins插件使用小结

    jenkins官网:https://wiki.jenkins-ci.org/display/JENKINS/Building+a+software+project jenkins插件: 1.AnsiC ...

  10. Google 商店:您的应用静态链接到的 OpenSSL 版本有多个安全漏洞。建议您尽快更新 OpenSSL

    安全提醒 您的应用静态链接到的 OpenSSL 版本有多个安全漏洞.建议您尽快更新 OpenSSL. 在开头为 1.0.1h.1.0.0m和 0.9.8za的 OpenSSL 版本中这些漏洞已得到修复 ...