MVC下form表单一次上传多种类型的图片(每种类型的图片可以上传多张)
form表单一次上传多种类型的图片(每种类型的图片可以上传多张)
controller中的action方法
public ActionResult UploadImage( )
{
int imageType=(int)Request.Form["ImageType"];
//整体图片集合
IList<HttpPostedFileBase> wholePictureIList = Request.Files.GetMultiple("WholePicture");//HttpPostedFileBase:充当类的基类,这些类提供对客户端上传的文件的单独访问;Request.Files.GetMultiple(string name):返回与name匹配的所有文件
//周边图片集合
IList<HttpPostedFileBase> AroundSupportPictureIList = Request.Files.GetMultiple("AroundSupportPicture");
if (wholePictureIList[0].FileName != "")
{
foreach (var item in wholePictureIList)
{
byte[] b = new byte[item.ContentLength];
item.InputStream.Read(b, 0, item.ContentLength);
model.WholePicture.Add(b);//model.WholePicture是byte[]的集合,即图片的流文件,可以存到数据库中
}
}
if (AroundSupportPictureIList[0].FileName != "")
{
foreach (var item in AroundSupportPictureIList)
{
byte[] b = new byte[item.ContentLength];
item.InputStream.Read(b, 0, item.ContentLength);
model.AroundSupportPicture.Add(b);
}
}
int userId = (int)Session["UserId"];
ManageParkPediaService service = new ManageParkPediaService();
StateInfo<int> infoT = service.SaveImage(model, userId);
return Json(infoT);
}
view中的代码
引入<script src="~/Scripts/jquery.form.js"></script>
<script type="text/javascript">
//上传图片
function uploadImage() {
console.log(222);
$('#fileForm').ajaxSubmit({
success: function (msg) {
console.log(msg);
}
});
}
</script>
<form id="fileForm" method="post" action="http://localhost:38594/UploadImage/SaveImageResult" enctype="multipart/form-data">
<input type="text" name="ImageType" id="ImageType" value="1" />
<input type="file" name="WholePicture" id="WholePicture" readonly multiple />
<input type="file" name="AroundSupportPicture" id="AroundSupportPicture" readonly multiple />
<input type="button" onclick="uploadImage()" value="上传图片" />
</form>
MVC下form表单一次上传多种类型的图片(每种类型的图片可以上传多张)的更多相关文章
- MVC中Form表单的提交
概述 Web页面进行Form表单提交是数据提交的一种,在MVC中Form表单提交到服务器.服务端接受Form表单的方式有多种,如果一个Form有2个submit按钮,那后台如何判断是哪个按钮提交的数据 ...
- 今天在研究jquery用ajax提交form表单中得数据时,学习到了一种新的提交方式
今天在研究jquery用ajax提交form表单中得数据时,学习到了一种新的提交方式 jquery中的serialize() 方法 该方法通过序列化表单值,创建 URL 编码文本字符串 序列化的值可在 ...
- Ajax模拟Form表单提交,含多种数据上传
---恢复内容开始--- Ajax提交表单.使用FormData提交表单数据和上传的文件(这里的后台使用C#获取,你可以使用Java一样获取) 有时候前台的数据提交到后台,不想使用form表单上传,希 ...
- 关于Form表单一些基础知识
1.两个重要属性: action:表单需要提交的服务器地址 method:表单提交数据使用的方法,get/post >>>get和post的区别 ①get传参使用URL传递,所有参数 ...
- ASP.NET MVC 与Form表单交互
一,Form包含文件类(单选文件) <form id="ImgForm" method="POST" enctype="multipart/fo ...
- Request.getparameternames 获取form表单里面所有的请求参数 。 返回一个Enumeration类型的枚举.
通过Enumeration的hasMoreElements()方法遍历.再由nextElement()方法获得枚举的值.此时的值是form表单中所有控件的name属性的值. 最后通过request.g ...
- flask通过form表单一次上传多个文件
基本上,用了flask官网的示例代码(中文版,英文版),稍微做了修改. import os from flask import Flask, flash, request, redirect, url ...
- layui中进行form表单一些问题
最近一段时间一直在用layui来写一些前段页面,发现有几个问题,不知道是我的编译器的问题还是什么,总之目前是自己改成功了,在这里分享下. 第一个是用layui去写单选按钮,网页上不会显示出来.解决方法 ...
- mvc中form表单提交的几种形式
第一种方式:submit 按钮 提交 <form action="MyDemand" method="post"> <span>关键字: ...
随机推荐
- 算法录 之 BFS和DFS
说一下BFS和DFS,这是个比较重要的概念,是很多很多算法的基础. 不过在说这个之前需要先说一下图和树,当然这里的图不是自拍的图片了,树也不是能结苹果的树了.这里要说的是图论和数学里面的概念. 以上概 ...
- 那些学些网址_jquery初学知识
http://www.cnblogs.com/mingmingruyuedlut/archive/2011/10/18/2216553.html(ajax)http://www.enet.com.cn ...
- 自制ichartjs饼图
饼图:2个数据: <!DOCTYPE html> <html> <head> <meta charset="UTF-8" /> &l ...
- javascript 中 function bind()
Function bind() and currying <%-- All JavaScript functions have a method called bind that binds t ...
- 关于iOS性能调优
性能调优一直都是作为高阶iOS开发者的一个入门门槛,下面我搜集了日常查阅资料中见到的各种高质量调优博文,仅供参考 UIKit性能调优实战讲解 iOS 高效添加圆角效果实战讲解
- Centos rsync文件同步配置
一.服务器端配置: # yum -y install xinetd CentOS默认已经安装了rsync 服务.. 输入 rsync 命令可查看是否安装. # vi /etc/xinetd.d ...
- URL中有中文字符,转码方法
服务端返回的urlString里面有时含有中文,使用 [NSURL URLWithString:urlString]生成URL对象时,iOS客户端不能正确进行网络请求,网上找到的URLEncode方法 ...
- MYSQL一次性能优化实战经历[转]
每次经历数据库性能调优,都是对性能优化的再次认识.对自己知识不足的有力验证,只有不断总结.学习才能少走弯路. 一.性能问题描述 应用端反应系统查询缓慢,长时间出不来结果.SQLServer数据库服务器 ...
- 设计模式笔记之二:Android开发中的MVP架构(转)
写在前面,本博客来源于公众号文章:http://mp.weixin.qq.com/s?__biz=MzA3MDMyMjkzNg==&mid=402435540&idx=1&sn ...
- Servlet_ResponseHeader
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletExcepti ...