在Asp.net的MVC中利用swupload实现多图片上

2019-10-19     科技i关注

这篇文章主要为大家详细介绍了Asp.net MVC使用swupload实现多图片上传功能,具有一定的参考价值,感兴趣的小伙伴们可以参考一下

本文实例为大家分享了swupload实现多图片上传的具体代码,供大家参考,具体内容如下

1. 下载WebUploader

2. 将下载到的压缩包里面的文件复制到自己的项目中

3. 添加引用







4.准备一个放图片的容器和一个上传按钮



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.CreateDirectory(localPath);
}
file.SaveAs(Path.Combine(localPath, filePathName));
return Json(new
{
jsonrpc = "2.0",
id = id,
filePath = "/Upload/" + filePathName
});

}

这样就大功告成了。

以上就是在Asp.net的MVC中利用swupload实现多图片上传功能的实例详解的详细内容,更多请关注其它相关文章!

更多技巧请《转发 + 关注》哦!

文章来源: https://twgreatdaily.com/zh-hans/NLPA4G0BMH2_cNUg3ap0.html