在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-cn/NLPA4G0BMH2_cNUg3ap0.html