public ActionResult Upload() { HttpPostedFileBase file = Request.Files["file1"]; int id = Int32.Parse(Request.Form["carID"]); //存入文件 if (file.ContentLength > 0) { file.SaveAs(Server.MapPath("~/UploadImg/") + System.IO.Path.GetFileName(file.FileName)); string url = System.IO.Path.GetFileName(file.FileName); CarImgBll bll=new CarImgBll(); bll.AddCarImg(id, url); return RedirectToAction("UploadSuccess", "Page"); } else { return RedirectToAction("UploadFaile", "Page"); } }
/// <summary> /// 新添加一条车辆出售记录 /// </summary> /// <param name="brand"></param> /// <param name="carType"></param> /// <param name="price"></param> /// <param name="color"></param> /// <param name="year"></param> /// <returns></returns> public ActionResult AddCar(string brand,string carType,decimal price,string color,int year) { var session = Session["logID"]; if (session==null) { return RedirectToAction("Login", "Home"); } else { //================================================================= int userid = Int32.Parse(session.ToString()); CarBll bll=new CarBll(); int result = bll.AddCar(userid, brand, carType, price, color, year, "在售"); if (result==1) { CarSaleEntities context=new CarSaleEntities(); var car = context.Car.OrderByDescending(c => c.ID).First(); int carid = car.ID;//获取车辆ID HttpPostedFileBase file = Request.Files["file1"];//获取提交上来的图片文件 //存入文件 if (file.ContentLength > 0) { file.SaveAs(Server.MapPath("~/CarImgs/") + System.IO.Path.GetFileName(file.FileName)); string url = System.IO.Path.GetFileName(file.FileName); CarImgBll imgBll = new CarImgBll(); imgBll.AddCarImg(carid, url); return RedirectToAction("MyCars"); } else { return RedirectToAction("Failed", "PageHelper"); } } else { return RedirectToAction("Failed", "PageHelper"); } } }