这篇文章主要为大家详细介绍了Asp.net MVC使用swupload实现多图片上传功能,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
本文实例为大家分享了swupload实现多图片上传的具体代码,供大家参考,具体内容如下
1. 下载WebUploader
2. 将下载到的压缩包里面的文件复制到自己的项目中
3. 添加引用
<!--引入Jquery--><!--引入Css--><!--引入Js-->
4.准备一个放图片的容器和一个上传按钮
<div id="fileList"></div><!--这是存放图片的容器--><div class="cp_img_jia" id="filePicker"></div><!--这是上传按钮-->
5.创建Web Uploader实例并监听事件
6 在Controller里新建一个Action用于保存图片并返回图片路径(这方法是 eflay 前辈博客上说的)
public ActionResult UpLoadProcess(string id, string name, string type, string lastModifiedDate, int size, HttpPostedFileBase file) { string filePathName = string.Empty; string localPath = Path.Combine(HttpRuntime.AppDomainAppPath, "Upload"); if (Request.Files.Count == 0) { return Json(new { jsonrpc = 2.0, error = new { code = 102, message = "保存失败" }, id = "id" }); } string ex = Path.GetExtension(file.FileName); filePathName = Guid.NewGuid().ToString("N") + ex; if (!System.IO.Directory.Exists(localPath)) { System.IO.Directory.CreateDirecto<strong style="color:transparent">来源gaodai#ma#com搞@@代~&码网</strong>ry(localPath); } file.SaveAs(Path.Combine(localPath, filePathName)); return Json(new { jsonrpc = "2.0", id = id, filePath = "/Upload/" + filePathName }); }
这样就大功告成了。
由于是第一次写博客,里面如果有写的不详细或不对的地方,欢迎大家指点。希望能和大家一起进步。
源码下载:swupload实现多图片上传
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持gaodaima搞代码网。
以上就是Asp.net MVC使用swupload实现多图片上传功能的详细内容,更多请关注gaodaima搞代码网其它相关文章!