jquery.uploadify.js怎么改变图片回显的顺序,就是上传的第一张在第一位,最后一个在最后 40
1个回答
展开全部
后台方法:
public JsonResult Handler(string guid, string dir = "Patent")
{
try
{
var filePath = "/Upload/" + dir + "/Img/";
var relativeUrls = new List<string>();
var imageIDs = new List<int>();
foreach (string f in Request.Files)
{
Image image = new Image();
image.Guid = Guid.Parse(guid);
//获取提交的文件
HttpPostedFileBase postFile = Request.Files[f];
if (postFile.ContentLength == 0)
continue;
var fileExtension = Path.GetExtension(postFile.FileName);
if (!Directory.Exists(Server.MapPath(filePath)))
{
Directory.CreateDirectory(Server.MapPath(filePath));
}
var fileName = Guid.NewGuid().ToString("N");
image.Name = fileName;
// 组合文件存储的相对路径
var relativeUrl = filePath + fileName + fileExtension;
image.Url = relativeUrl;
// 将相对路径转换成物理路径
var path = Server.MapPath(relativeUrl);
postFile.SaveAs(path);
imageRepository.Add(image);
imageRepository.Save();
imageIDs.Add(image.ID);
relativeUrls.Add(relativeUrl);
}
return Json(new { state = true, msg = "上传成功", imageUrl = relativeUrls, IDS = imageIDs }, JsonRequestBehavior.DenyGet);
}
catch
{
}
return Json(new { state = false, msg = "上传失败" }, JsonRequestBehavior.DenyGet);
}
//上传图片
$("#fileuploader").uploadFile({
url: '@Url.Content("~/Upload/Handler?guid=")' + patentGuid,
dragDrop: false,
fileName: "file",
showProgress: false,
onSuccess: function (files, response, xhr) {
if (response.state) {
$(".am-u-sm-9 .ajax-file-upload-statusbar").remove();
//按顺序展示你的图片
addImg(response.imageUrl, response.ID);
} else {
alert(response.msg);
}
}
});
public JsonResult Handler(string guid, string dir = "Patent")
{
try
{
var filePath = "/Upload/" + dir + "/Img/";
var relativeUrls = new List<string>();
var imageIDs = new List<int>();
foreach (string f in Request.Files)
{
Image image = new Image();
image.Guid = Guid.Parse(guid);
//获取提交的文件
HttpPostedFileBase postFile = Request.Files[f];
if (postFile.ContentLength == 0)
continue;
var fileExtension = Path.GetExtension(postFile.FileName);
if (!Directory.Exists(Server.MapPath(filePath)))
{
Directory.CreateDirectory(Server.MapPath(filePath));
}
var fileName = Guid.NewGuid().ToString("N");
image.Name = fileName;
// 组合文件存储的相对路径
var relativeUrl = filePath + fileName + fileExtension;
image.Url = relativeUrl;
// 将相对路径转换成物理路径
var path = Server.MapPath(relativeUrl);
postFile.SaveAs(path);
imageRepository.Add(image);
imageRepository.Save();
imageIDs.Add(image.ID);
relativeUrls.Add(relativeUrl);
}
return Json(new { state = true, msg = "上传成功", imageUrl = relativeUrls, IDS = imageIDs }, JsonRequestBehavior.DenyGet);
}
catch
{
}
return Json(new { state = false, msg = "上传失败" }, JsonRequestBehavior.DenyGet);
}
//上传图片
$("#fileuploader").uploadFile({
url: '@Url.Content("~/Upload/Handler?guid=")' + patentGuid,
dragDrop: false,
fileName: "file",
showProgress: false,
onSuccess: function (files, response, xhr) {
if (response.state) {
$(".am-u-sm-9 .ajax-file-upload-statusbar").remove();
//按顺序展示你的图片
addImg(response.imageUrl, response.ID);
} else {
alert(response.msg);
}
}
});
更多追问追答
追问
我只要修改前台代码就ok了?
追答
是的,后台返回的数据是按照上传图片的顺序组织的。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询