不同路径上传图片,列表显示问题


  1 
2
"uploadForm" action="Upload" method="post" enctype="multipart/form-data"> 3 4 5 6 7 18 19 20
class="td03" style="padding-top: 18px; vertical-align: top">class="xxx">*产品图片 class="td02" style="padding-top: 9px"> 8
class="upload"> 9 "button" id="btnbra" class="btn" onclick="browerfilebrand.click()" value="上传"> 10 "file" id="browerfilebrand" class="upload-input-filebra" name="fileupload" accept="image/gif, image/jpeg" multiple="multiple" value=""> 11
class="img_center" id="braimage"> 12 "~/Images/@ViewBag.image" class="bra-img"> 13
14 "true" name="imgname" type="hidden" value="@ViewBag.image" /> 15
16
class="tip">建议图片尺寸为600*600像素以上正方形,图片请避免全文字
17
21
22
"SaveBrand" class="fabu"> 23 保存 24
25
26 27 52 53 54 [HttpPost] 55 public JsonResult UploadImage(FormCollection collection) 56 { 57 if (Request.Files.Count > 0) 58 { 59 if (Request.Files.Count == 1) 60 { 61 HttpPostedFileBase file = Request.Files[0]; 62 if (file.ContentLength > 0) 63 { 64 string title = string.Empty; 65 66 title = DateTime.Now.ToString("yyyyMMddHHmmss") + "_" + Path.GetFileName(file.FileName); 67 string path = "../Images/" + title; 68 string sendimgstr = "/Images/" + title; 69 path = System.Web.HttpContext.Current.Server.MapPath(path); 70 file.SaveAs(path); 71 72 string bId = collection["brandid"];//品牌ID 73 string bName = collection["BrandName"];//品牌名称 74 string bInfo = collection["BrandInfo"];//品牌网址 75 string bImage = title;//品牌图片 76 string CatId = collection["CatalogID"];//所属类别 77 DataTable dt = null; 78 string astr = DAL.BrandInfo.GetBrandName(bName); 79 80 if (!string.IsNullOrEmpty(bId) && !string.IsNullOrEmpty(bName) && !string.IsNullOrEmpty(bImage) && !string.IsNullOrEmpty(CatId)) 81 { 82 if (astr != "0") //存在此品牌,给出提示 83 { 84 //执行修改品牌 85 dt = DAL.BrandInfo.UpdateBrand(bId, bName, bInfo, bImage, CatId); 86 } 87 else //执行上传品牌 88 { 89 dt = DAL.BrandInfo.AddBrand(bId, bName, bInfo, bImage, CatId); 90 } 91 } 92 else 93 { 94 //执行上传品牌 95 dt = DAL.BrandInfo.AddBrand(bId, bName, bInfo, bImage, CatId); 96 } 97 98 if (astr != "0") 99 { 100 return Json(new { status = true, url = sendimgstr, msg = "" }); 101 } 102 else 103 { 104 return Json(new { status = true, url = sendimgstr, msg = "" }); 105 } 106 } 107 else 108 {//没有换图片的时候 109 string bId = collection["brandid"];//品牌ID 110 string bName = collection["BrandName"];//品牌名称 111 string bInfo = collection["BrandInfo"];//品牌网址 112 string bImage = collection["imgname"];//品牌图片 113 string CatId = collection["CatalogID"];//所属类别 114 DataTable dt = null; 115 string astr = DAL.BrandInfo.GetBrandName(bName); 116 117 if (!string.IsNullOrEmpty(bId) && !string.IsNullOrEmpty(bName) && !string.IsNullOrEmpty(bImage) && !string.IsNullOrEmpty(CatId)) 118 { 119 if (astr != "0") //存在此品牌,给出提示,不执行操作 120 { 121 //执行修改品牌 122 dt = DAL.BrandInfo.UpdateBrand(bId, bName, bInfo, bImage, CatId); 123 } 124 else //执行上传品牌 125 { 126 dt = DAL.BrandInfo.AddBrand(bId, bName, bInfo, bImage, CatId); 127 } 128 } 129 else 130 { 131 //执行修改品牌 132 dt = DAL.BrandInfo.UpdateBrand(bId, bName, bInfo, bImage, CatId); 133 } 134 if (astr != "0") 135 { 136 string sendimgstr = "/Images/" + bImage; 137 return Json(new { status = true, url = sendimgstr, msg = "" }); 138 } 139 else 140 { 141 string sendimgstr = "/Images/" + bImage; 142 return Json(new { status = true, url = sendimgstr, msg = "" }); 143 } 144 145 } 146 } 147 else 148 { 149 string[] urllist = new string[Request.Files.Count]; 150 for (int i = 0; i < Request.Files.Count; i++) 151 { 152 HttpPostedFileBase file = Request.Files[i]; 153 if (file.ContentLength > 0) 154 { 155 string title = string.Empty; 156 title = DateTime.Now.ToString("yyyyMMddHHmmss") + "_" + Path.GetFileName(file.FileName); 157 string path = "../Images/" + title; 158 path = System.Web.HttpContext.Current.Server.MapPath(path); 159 file.SaveAs(path); 160 urllist[i] = path; 161 } 162 } 163 return Json(new { status = true, url = urllist }); 164 } 165 166 } 167 else 168 { 169 return Json(new { status = false, url = "", msg = "没有文件" }); 170 } 171 //return Json(new { status = false, url = "", msg = "" }); 172 }