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>关键字: ...
随机推荐
- Mysql 技巧
order by条件: SELECT * FROM tablename WHERE id_one=27 OR id_two=27 ORDER BY CASE WHEN id_one=27 THEN t ...
- openstack名称发音收集
MariaDB: maria['mɛərɪr] Corosync: coro[kə'roʊ] sync[sɪŋk] pacemaker: [ˈpesˌmekɚ] galera: ...
- (中等) HDU 1043 Eight,经典搜索问题。
Problem Description The 15-puzzle has been around for over 100 years; even if you don't know it by t ...
- Mysql中Insert into xxx on duplicate key update问题
要点:Insert into xxx on duplicate key update可以在唯一索引重复的情况下,进行更新操作. (1) 插入里边的字段应该只有一个 唯一索引: ...
- 组织Golang代码
本月初golang官方blog(需要自己搭梯子)上发布了一篇文章,简要介绍了近几个月Go在一 些技术会议上(比如Google I/O.Gopher SummerFest等)的主题分享并伴有slide链 ...
- UIImageView控件
UIImageView是用于显示图像的,在iOS开发中,我们无需专门去写什么代码,不需要检查设备的类型,只需要把1x.2x.3x的图像添加到项目中,图像视图会自动的在正确的时间加载正确的图像. (1) ...
- struts2拦截器-自定义拦截器,放行某些方法(web.xml配置)
一.web.xml配置 <filter> <filter-name>encodingFilter</filter-name> <filter-class> ...
- STM32中的位带(bit-band)操作(转)
源:STM32中的位带(bit-band)操作 支持了位带操作后,可以使用普通的加载/存储指令来对单一的比特进行读写.在 CM3 中,有两个区中实现了位带.其中一个是 SRAM 区的最低 1MB 范围 ...
- VB.NET中网络编程的另一种方案----system.net中的HttpWebRequest类的使用
VB.NET中网络编程的另一种方案---- system.net中的HttpWebRequest类的使用 在VB.net中进行网络编程,除了我之前写的随笔中的使用WinHttp组件进行编程,还有另一种 ...
- Android与JNI(二) ---- Java调用C++ 动态调用
目录: 1. 简介 2. JNI 组件的入口函数 3. 使用 registerNativeMethods 方法 4. 测试 5. JNI 帮助方法 6. 参考资料 1. 简介 Android与JNI( ...