ajaxSubmit 文件上传

from 设定(input根据自己情况而定),
enctype="multipart/form-data"一定要设定,否则默认只提交文本


ajaxSubmit 需引入jquery.form.js

$("#xx_User_content_qianming").ajaxSubmit({
                    type: 'POST', url: '后台方法路径', success: function (result) {
                        console.log(result);
                        if (result.s) {
                            com.message('s', result.message);
                            km.xx_User.reload();
                        } else {
                            com.message('e', result.message);
                        }
                    }
                });

.net mvc 后台方法

public JsonResult SaveUserInfo()
        {
            string p = Server.MapPath("/");
            //判断是否存在文件
            if (Request.Files.Count>0)
            {
                p = p + "\\data\\电子签名\\" +  Request.Params["department_id"].ToString().ToString() ;
                var savePath=p+ "\\" + Request.Params["id"].ToString() + "_qianming.png";
                if (!System.IO.Directory.Exists(p))
                    System.IO.Directory.CreateDirectory(p);
                //文件保存
                Request.Files[0].SaveAs(savePath);
            }
        return JsonNet(new { s = 1, msg="ok" });
    }
posted @ 2020-04-24 14:54  唯爱金生  阅读(783)  评论(0编辑  收藏  举报