jQuery异步上传文件插件ajaxFileUpload详细介绍

2020-05-22 17:07:14易采站长站整理

                    },
                    error: function (data, status, e)//服务器响应失败处理函数
                    {
                        alert(e);
                    }
                }
            )
            return false;
        }
    </script>
</head>
<body>
    <p><input type=”file” id=”file1″ name=”file” /></p>
    <input type=”button” value=”上传” />
    <p><img id=”img1″ alt=”上传成功啦” src=”” /></p>
</body>
</html>

 最后再来一个上传图片且附带参数的实例:控制器代码:

public class HomeController : Controller
    {
        public ActionResult Index()
        {
            return View();
        }

        public ActionResult Upload()
        {
            NameValueCollection nvc = System.Web.HttpContext.Current.Request.Form;

            HttpFileCollection hfc = System.Web.HttpContext.Current.Request.Files;
            string imgPath = “”;
            if (hfc.Count > 0)
            {
                imgPath = “/testUpload” + hfc[0].FileName;
                string PhysicalPath = Server.MapPath(imgPath);
                hfc[0].SaveAs(PhysicalPath);
            }