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表单一次上传多种类型的图片(每种类型的图片可以上传多张)的更多相关文章

  1. MVC中Form表单的提交

    概述 Web页面进行Form表单提交是数据提交的一种,在MVC中Form表单提交到服务器.服务端接受Form表单的方式有多种,如果一个Form有2个submit按钮,那后台如何判断是哪个按钮提交的数据 ...

  2. 今天在研究jquery用ajax提交form表单中得数据时,学习到了一种新的提交方式

    今天在研究jquery用ajax提交form表单中得数据时,学习到了一种新的提交方式 jquery中的serialize() 方法 该方法通过序列化表单值,创建 URL 编码文本字符串 序列化的值可在 ...

  3. Ajax模拟Form表单提交,含多种数据上传

    ---恢复内容开始--- Ajax提交表单.使用FormData提交表单数据和上传的文件(这里的后台使用C#获取,你可以使用Java一样获取) 有时候前台的数据提交到后台,不想使用form表单上传,希 ...

  4. 关于Form表单一些基础知识

    1.两个重要属性: action:表单需要提交的服务器地址 method:表单提交数据使用的方法,get/post >>>get和post的区别 ①get传参使用URL传递,所有参数 ...

  5. ASP.NET MVC 与Form表单交互

    一,Form包含文件类(单选文件) <form id="ImgForm" method="POST" enctype="multipart/fo ...

  6. Request.getparameternames 获取form表单里面所有的请求参数 。 返回一个Enumeration类型的枚举.

    通过Enumeration的hasMoreElements()方法遍历.再由nextElement()方法获得枚举的值.此时的值是form表单中所有控件的name属性的值. 最后通过request.g ...

  7. flask通过form表单一次上传多个文件

    基本上,用了flask官网的示例代码(中文版,英文版),稍微做了修改. import os from flask import Flask, flash, request, redirect, url ...

  8. layui中进行form表单一些问题

    最近一段时间一直在用layui来写一些前段页面,发现有几个问题,不知道是我的编译器的问题还是什么,总之目前是自己改成功了,在这里分享下. 第一个是用layui去写单选按钮,网页上不会显示出来.解决方法 ...

  9. mvc中form表单提交的几种形式

    第一种方式:submit 按钮 提交 <form action="MyDemand" method="post"> <span>关键字: ...

随机推荐

  1. Python 100例(下)

    如果你坚持到这了,哪就为自己鼓掌吧!坚持,你一定可以. 实例51: 题目:学习使用按位与&. #!/usr/bin/env  python# --*--coding:utf-8 --*--'' ...

  2. gnome3 no launcher

    http://askubuntu.com/questions/43246/how-to-configure-gnome-3-to-show-icons-on-desktop http://superu ...

  3. 转 互联网推送服务原理:长连接+心跳机制(MQTT协议)

    http://blog.csdn.net/zhangzeyuaaa/article/details/39028369 目录(?)[-] 无线移动网络的特点 android系统的推送和IOS的推送有什么 ...

  4. highcharts第一篇---简介和使用

    Highcharts 是一个用纯JavaScript编写的一个图表库, 能够很简单便捷的在web网站或是web应用程序添加有交互性的图表,并且免费提供给个人学习.个人网站和非商业用途使用.HighCh ...

  5. static DEVICE_ATTR(val, S_IRUGO | S_IWUSR, hello_val_show, hello_val_store); 的作用

    在 老罗的android例程里面有 static DEVICE_ATTR(val, S_IRUGO | S_IWUSR, hello_val_show, hello_val_store); /*读取设 ...

  6. python_eval的用法

    1. eval用法: 将字符串str当成有效的表达式来求值并返回计算结果. 2. eval的功能: math当成一个计算器很好用. 将字符串转换为list,tuple,dict. 3. 举例 # -* ...

  7. MediaScanner

    http://blog.csdn.net/hellofeiya/article/details/8255898 http://www.cnblogs.com/halzhang/archive/2011 ...

  8. (简单) UVA 11624 Fire! ,BFS。

    Description Joe works in a maze. Unfortunately, portions of the maze have caught on fire, and the ow ...

  9. 3505: [Cqoi2014]数三角形

    3505: [Cqoi2014]数三角形 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 1324  Solved: 807[Submit][Statu ...

  10. Codeforces#360Div2

    A题 题意:给定d个操作,每个操作当中只包含1和0,若存在0,则表示操作者获胜,求最大的连续获胜个数 分析:直接统计之后用一个数组纪录下来即可 #include <iostream> #i ...