public ActionResult save(merchantext ext, HttpPostedFileBase file_input) { var ses = Convert.ToInt64(Session["sesMerchantID"]); var mer = db.merchants.Find(ses); try { if (file_input != null && file_input.ContentLength > 0) { string fileName = DateTime.Now.ToString("yyyyMMddHHmmss") + "-" + Path.GetFileName(file_input.FileName); string filePath = Path.Combine(Server.MapPath("~/Upload"), fileName); file_input.SaveAs(filePath); mer.pic = "~/Upload/" + fileName; mer.name = ext.name; mer.notice = ext.notice; mer.join_full_reduce = (ext.join_full_reduce1); mer.join_discount = (ext.join_discount1); mer.join_buy_gift = (ext.join_buy_gift1); db.SaveChanges(); return(RedirectToAction("Index", getAllMerchant())); } else { return(Content("没有文件!", "text/plain")); } } catch { return(Content("上传异常 !", "text/plain")); } }
public ActionResult upload(merchantext ext, HttpPostedFileBase image) { var mer = db.merchants.Find((long)Session["sesMerchantID"]); var merext = new merchantext { id = mer.id, name = mer.name, pic = mer.pic, notice = mer.notice, join_full_reduce1 = (mer.join_full_reduce == null) ? false : ((bool)mer.join_full_reduce ? true : false), join_discount1 = (mer.join_discount == null) ? false : ((bool)mer.join_discount ? true : false), join_buy_gift1 = (mer.join_buy_gift == null) ? false : ((bool)mer.join_buy_gift ? true : false), }; try { if (image != null && image.ContentLength > 0) { string fileName = DateTime.Now.ToString("yyyyMMdd") + "-" + Path.GetFileName(image.FileName); string filePath = Path.Combine(Server.MapPath("~/Upload"), fileName); image.SaveAs(filePath); mer.pic = "~/Upload/" + fileName; db.SaveChanges(); merext.pic = mer.pic; } else { return(Content("没有文件!", "text/plain")); } return(RedirectToAction("Index", merext)); } catch { return(Content("上传异常 !", "text/plain")); } //var fileName = Path.Combine(Request.MapPath("~/Upload"), Path.GetFileName(file.FileName)); //try //{ // File.SaveAs(fileName); // //tm.AttachmentPath = fileName;//得到全部model信息 // tm.pic = "../upload/" + Path.GetFileName(File.FileName); // //return Content("上传成功!", "text/plain"); // return RedirectToAction("Show", tm); //} //catch //{ // return Content("上传异常 !", "text/plain"); //} }
public merchantext getAllMerchant() { var mer = db.merchants.Find((long)Session["sesMerchantID"]); var merext = new merchantext { id = mer.id, name = mer.name, pic = mer.pic, notice = mer.notice, join_full_reduce1 = (mer.join_full_reduce == null) ? false : ((bool)mer.join_full_reduce ? true : false), join_discount1 = (mer.join_discount == null) ? false : ((bool)mer.join_discount ? true : false), join_buy_gift1 = (mer.join_buy_gift == null) ? false : ((bool)mer.join_buy_gift ? true : false), }; return(merext); }