我必須查看一個(gè)用于創(chuàng)建,另一個(gè)用于編輯數(shù)據(jù)庫(kù)中的記錄。記錄包含圖片...我的問題是編輯。每次我要編輯記錄時(shí),我都必須重新選擇圖片。我怎樣才能讓控制器保持舊值?我試圖給輸入一個(gè)默認(rèn)值,但我發(fā)現(xiàn)我不能public ActionResult Edit(Carousel carousel,HttpPostedFileBase picture) { string path = Path.Combine(Server.MapPath("~/Images"), picture.FileName); if (ModelState.IsValid) { picture.SaveAs(path); carousel.Picture = picture.FileName; db.Entry(carousel).State = EntityState.Modified; db.SaveChanges(); return RedirectToAction("Index"); } return View(carousel); }
1 回答
慕標(biāo)5832272
TA貢獻(xiàn)1966條經(jīng)驗(yàn) 獲得超4個(gè)贊
你不能保留圖像input type="file",你需要顯示圖像<img src="@Model.Image" />
在 cshtml 編輯文件中:
<input type="file" name="image" /> <img src="@Model.Image" alt="my image" />
- 1 回答
- 0 關(guān)注
- 96 瀏覽
添加回答
舉報(bào)
0/150
提交
取消
