public ActionResult Index()
{
return View();
}
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
});
}
模板代码:
@{
Layout = null;
}
多图片上传页
图片上传:
此外还用到了模板中引用的css和js代码,详见附件
备注:css中关于图片的引用请根据自己的路径,修改图片地址
参考:http://www.cnblogs.com/ismars/p/4176912.html
稍有改动,如果对此控件有兴趣可到官方了解