前端:

js:
        function AjaxKouBeiShopEdit() {

var options = {
                dataType: "json",
                success: function (data) {
                    alert(data);
                 
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    console.log(textStatus);
                    console.log(errorThrown);
                }
            };
          
            $("#ShopForm").ajaxSubmit(options);

}

html:

<form class="form-horizontal" id="ShopForm" action="你的控制器/AjaxKouBeiShopEdit" method="post" enctype="multipart/form-data">

<input type="file"  name="ProductImg" class="fileData"    />

<input type="file"  name="ProductImg" class="fileData"    />

</form>

后端:
        /// <summary>
        /// 口碑门店-添加
        /// </summary>
        /// <param name="upImg"></param>
        /// <param name="entity"></param>
        /// <returns></returns>
        [HttpPost]
        public string AjaxKouBeiShopEdit(KouBeiShopModel entity)
        {
            StringBuilder sqlStr = new StringBuilder();
            TimeSpan timeSpan = (DateTime.Now - TimeZone.CurrentTimeZone.ToLocalTime(new System.DateTime(1970, 1, 1)));
            Random random = new Random();
            JObject resultJsonerr = new JObject();
            //修改操作
                #region  添加文件
                string filePhysicalPath = @"D:/yyyy/";
                string MainImgName = "";

//详细图片路径
                if (Request.Files.Count != 0)
                {
                    MainImgName = filePhysicalPath + MainImgName;
                    try
                    {
                        for (int i = 0; i < Request.Files.Count;i++ )
                        {
                            HttpPostedFileBase uploadFile = Request.Files[i] as HttpPostedFileBase;
                            if (uploadFile != null && uploadFile.ContentLength > 0)
                            {
                              //  if (i==0)//首图
                             //   {
                                //html 上至下加载,file  input
                             //   }
         //随机名称
                                long t2 = (long)timeSpan.TotalSeconds;
                                int n2 = random.Next(10000, 99999);
                                string extension = Path.GetExtension(uploadFile.FileName);
                                string ImgListName = t2 + "" + n2 + extension;
                                var path = Path.Combine(filePhysicalPath, ImgListName);
                                uploadFile.SaveAs(path);
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        resultJsonerr.Add("State", -1);
                        return "添加失败";
                    }
                }

  
            return "添加成功";

}

2017-12-1  提示:

HttpPostedFileBase是有序的,按照HTML加载方式来确定索引,从而可以控制首图附属图等等。

ASP.NET图片上传(配合jquery.from.js 插件)的更多相关文章

  1. asp.net图片上传实例

    网站后台都需要有上传图片的功能,下面的例子就是实现有关图片上传. 缺点:图片上传到本服务器上,不适合大量图片上传. 第一.图片上传,代码如下: xxx.aspx 复制代码代码如下: <td cl ...

  2. Asp.NetCoreWebApi图片上传接口(二)集成IdentityServer4授权访问(附源码)

    写在前面 本文地址:http://www.cnblogs.com/yilezhu/p/9315644.html 作者:yilezhu 上一篇关于Asp.Net Core Web Api图片上传的文章使 ...

  3. ASP.NET图片上传和截取

    一.介绍:图片的上传直接使用ajax就可以了,截取图片的话使用到Jcrop插件. 图片上传资料:https://www.jb51.net/article/87654.htm 截取图片插件:http:/ ...

  4. ASP.NET 图片上传工具类 upload image简单好用功能齐全

    使用方法: UploadImage ui = new UploadImage(); /***可选参数***/ ui.SetWordWater = "哈哈";//文字水印 // ui ...

  5. ASP.NET- 无刷新上传使用jQuery插件之ajaxFileUpload

    灰常好,我已经使用过里面的代码了,可以用,原文地址:http://www.cnblogs.com/kissdodog/archive/2012/12/15/2819025.html 一.ajaxFil ...

  6. asp.net图片上传及删除

    方法一:UploadImage cetFU = new UploadImage(); if (cetFU.UpFile(FileUpload1, "teacher_picture" ...

  7. asp.net图片上传代码

    前端: <form action="/ImageUpload.ashx" method="post" enctype="multipart/fo ...

  8. 文件上传时jquery.form.js中提示form.submit SCRIPT5: 拒绝访问

    利用其它控件触发file的click事件来选择文件后,使用jquery.form.js中的submit方法提交时IE报错:form.submit SCRIPT5: 拒绝访问,其它浏览器正常, < ...

  9. ajax图片上传(asp.net +jquery+ashx)

    一.建立Default.aspx页面 <%@ Page Language="C#" AutoEventWireup="true"  CodeFile=&q ...

随机推荐

  1. CF3A Shortest path of the king

    The king is left alone on the chessboard. In spite of this loneliness, he doesn't lose heart, becaus ...

  2. vue的插槽slot

    插槽是写在子组件上,用啦留给父级添加内容的位置接口: 1. 父级里的 <template :is='子标签名'>父插入内容</template>标签,里的内容       sl ...

  3. mui 轮播

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta name ...

  4. python开发 *进程数据隔离.守护进程,进程同步工具 * 180725

    进程数据隔离.守护进程,进程同步工具 一.进程之间的数据隔离: from multiprocessing import Process n=100 #主程序中变量n= def func(): glob ...

  5. inner_product

    版本1: template < class InputIterator1, class InputIterator2, class T> T inner_product(InputIter ...

  6. SQL中什么时候需要使用游标?使用游标的步骤

    https://zhidao.baidu.com/question/568932670.html 例子table1结构如下id intname varchar(50) declare @id intd ...

  7. 2016ACM/ICPC亚洲区沈阳站 - A/B/C/E/G/H/I - (Undone)

    链接:传送门 A - Thickest Burger - [签到水题] ACM ICPC is launching a thick burger. The thickness (or the heig ...

  8. 移动前端开发和 Web 前端开发的区别

    http://www.itcast.cn/news/20180125/16033584753.shtml 1,普通PC端开发与移动端开发区别. 先说背景,我大言不惭的说一下,我pc端的前端开发干了有快 ...

  9. XSS笔记

    XSS测试代码: <img src="javascript:alert(/xss/)"> <script src=http://evil.com/xss.js&g ...

  10. PTA 树的遍历

    给定一棵二叉树的后序遍历和中序遍历,请你输出其层序遍历的序列.这里假设键值都是互不相等的正整数. 输入格式: 输入第一行给出一个正整数N(≤30),是二叉树中结点的个数.第二行给出其后序遍历序列.第三 ...