上传文件(单文件)(FormData)(前端代码+.NET服务器端)
由于样式需要不能直接用file,只能用文本框+按钮
<form class="form-horizontal form-bordered form-row-strippe" enctype="multipart/form-data" method="post" name="fileinfo" id="fileinfo" data-toggle="validator">
<div class="modal-body">
<div class="form-horizontal">
<div class="control-group">
<label class="control-label" style="width: 125px;">
审批项目名称:</label>
<div class="controls" style="margin-left: 0px;">
<input type="text" id="id" name="id" style="display:none;" value="$id$" />
<input type="text" id="projectname" name="projectname" class="m-wrap large" value="$projectname$" />
</div>
</div>
<div class="control-group">
<label class="control-label" style="width: 125px;">
审批项目说明:</label>
<div class="controls" style="margin-left: 0px;">
<input class="m-wrap large" type="text" id="projectinfo" name="projectinfo" value="$projectinfo$" />
</div>
</div>
<div class="control-group">
<label class="control-label" style="width: 125px;">
审批项目文件:</label>
<div class="controls" style="margin-left: 0px;">
<input type="file" id="filepath" name="filepath" style="display:none" onchange="changetext()" />
<input class="m-wrap" type="text" id="pathfile" name="pathfile" readonly="readonly" value="$filepath$" />
<input class="btn green" type="button" value="选择文件" id="uploadpath" />
</div>
</div>
</div>
</div>
<div class="modal-footer bg-info">
<input class="btn blue" type="button" id="btnsubmit" value="提交" onclick="update()" data-dismiss="modal" />
<button type="button" class="btn green" data-dismiss="modal">
取消</button>
</div>
</form>
(HTML)
<script type="text/javascript">
jQuery(document).ready(function () {
$('#uploadpath').click('click', function () {
$('#filepath').trigger('click');
});
})
function changetext()
{
if ($("#filepath").val() == "") {
//当用户没有选择文件时,不修改原有路径
}
else {
$("#pathfile").val($("#filepath").val());
}
}
function update() {
var projectname = $("#projectname").val();
var projectinfo = $("#projectinfo").val();
var filepath = $("#pathfile").val();
//var formData = new FormData($("#fileinfo")[0]);//两者皆可
var formData = new FormData(document.forms.namedItem("fileinfo"));
formData.append("id", $id$);
$.ajax({
url: "/ApprovalProcessNoView/queryeditproject",
type: "POST",
data: formData,
async: false,
cache: false,
contentType: false,
processData: false,
success: function (data) {
alert(data.msg);
},
error: function (data) {
alert(data.msg);
}
});
}
</script>
(JAVASCRIPT)
returnresult rr = new returnresult();
string projectname = Request.Form["projectname"];
string projectinfo = Request.Form["projectinfo"];
HttpPostedFileBase pathfile = Request.Files["filepath"];
long id = Request.Form["id"].ToLong(); string path = "/UF/Uploads/myfile";
//获取上传目录 转换为物理路径
string uploadPath = Server.MapPath(path);
//判断目录是否存在
if (!Directory.Exists(uploadPath))
{
Directory.CreateDirectory(uploadPath);
}
//保存文件的物理路径
string saveFile = uploadPath + pathfile.FileName;
//保存图片到服务器
try
{
pathfile.SaveAs(saveFile);
rr.status = true;
}
catch (Exception)
{
rr.status = false;
rr.msg = "文件上传失败";
}
(后台代码【C#】)
主要使用:FormData
效果:将文件和其他需要上传的数据一起上传
上传文件(单文件)(FormData)(前端代码+.NET服务器端)的更多相关文章
- SpringMVC文件上传下载(单文件、多文件)
前言 大家好,我是bigsai,今天我们学习Springmvc的文件上传下载. 文件上传和下载是互联网web应用非常重要的组成部分,它是信息交互传输的重要渠道之一.你可能经常在网页上传下载文件,你可能 ...
- Struts1文件上传、单文件、多文件上传【Struts1】
将struts1文件上传的操作汇总了一下,包括单文件上传和多文件上传,内容如下,留作备忘: Struts2实现文件上传的文章(http://blog.csdn.net/itwit/article/d ...
- Spring MVC-------文件上传,单文件,多文件,文件下载
Spring MVC 框架的文件上传是基于 commons-fileupload 组件的文件上传,只不过 Spring MVC 框架在原有文件上传组件上做了进一步封装,简化了文件上传的代码实现,取消了 ...
- SpringBoot - 实现文件上传1(单文件上传、常用上传参数配置)
Spring Boot 对文件上传做了简化,基本做到了零配置,我们只需要在项目中添加 spring-boot-starter-web 依赖即可. 一.单文件上传 1,代码编写 (1)首先在 stati ...
- flask 文件上传(单文件上传、多文件上传)
文件上传 在HTML中,渲染一个文件上传字段只需要将<input>标签的type属性设为file,即<input type=”file”>. 这会在浏览器中渲染成一个文件上传字 ...
- struts文件上传(单文件)
第01步:配置web.xml <?xml version="1.0" encoding="UTF-8"?> <web-app version= ...
- php文件上传之单文件上传
为了简单一些,php文件跟form表单写在了一个文件里. php单文件上传----> <!DOCTYPE html> <html> <head> <me ...
- java文件上传(单文件 多文件)与删除
/** * 文件上传--单文件 * * @param request * @param response * @param path * 文件存放路径(path为WebApp\后面的内容) * @re ...
- struts文件上传(多文件)
第01步:配置web.xml <?xml version="1.0" encoding="UTF-8"?> <web-app version= ...
- skymvc文件上传支持多文件上传
skymvc文件上传支持多文件上传 支持单文件.多文件上传 可以设定 文件大小.存储目录.文件类型 //上传的文件目录 $this->upload->uploaddir="att ...
随机推荐
- qsort函数用法【转】
qsort函数用法 qsort 功 能: 使用快速排序例程进行排序 用 法: void qsort(void *base, int nelem, int width, int (*fcmp)(con ...
- 转:Task任务调度实现生产者消费者模式
我们经常会遇到生产者消费者模式,比如前端各种UI操作事件触发后台逻辑等.在这种典型的应用场景中,我们可能会有4个业务处理逻辑(下文以P代表生产者,C代表消费者): 1. FIFO(先进先出) ...
- eclipse中运行项目时报Class not found的错误
环境:Groovy/Grails Tool Suite 3.1.0.RELEASE(BASED ON ECLIPSE JUNO 3.8.1).JDK1.6 运行class的main方法,或启动juni ...
- NOIP2015 跳石头
一年一度的“跳石头”比赛又要开始了! 这项比赛将在一条笔直的河道中进行,河道中分布着一些巨大岩石.组委会已经选择好了两块岩石作为比赛起点和终点.在起点和终点之间,有 N块岩石(不含起点和终点的岩石). ...
- UIKIT的简介
// // UIKIT各框架的简介 // IOS笔记 // // Created by 刘威成 on 13/12/14. // Copyright © 2015年 刘威成. All rights re ...
- Embedded database support
http://docs.spring.io/spring-framework/docs/3.0.0.M4/reference/html/ch12s08.html <jdbc:embedd ...
- elasticsearch【更新】操作
基于上一篇博文基础上,进行es的操作,document的新增比较简单,就不说了,这里主要说说更新操作. 更新操作,有两大类,一个是Replace,一个是Update,就是说一个是替换,一个是更新. 替 ...
- jquery中checkbox选中的问题之prop&attr惹的祸
一个网上很多的例子如下: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http: ...
- threadid=1: thread exiting with uncaught.exception ......解决方法
threadid=1: thread exiting with uncaught exception (group=0x40015560)E/AndroidRuntime(285): FATAL E ...
- FW开发代码规范---小任性(2)
三.空行 (1)在每个函数.结构体.枚举定义结束之后都要加空行. 在一个函数体内,逻辑密切相关的语句之间不加空行,其它地方应加空行分隔. struct st1 { - }; // 空行 enum { ...