私の問題私は単純だと信じていますが、私はそれに苦労しています。 イメージファイルをアップロードすると正常に動作しますが、データベースのパスはC:// user/pictures/blabla ....のように物理的なものになります。 仮想パス(〜/ ...)に変更したいと思います。 データベースパスを手動で仮想パスに変更すると、イメージが表示されます。 ご協力いただきありがとうございます。 は、ここに私のコードです:仮想パスの代わりに物理パスをデータベースに保存
CONTROLLER
public ActionResult Create(DriverReg model, HttpPostedFileBase file)
{
if (ModelState.IsValid)
{
if (file != null && file.ContentLength > 0)
{
var fileName = Path.GetFileName(file.FileName);
var phisicalPath = Path.Combine(Server.MapPath("~/Content/uploads/"), fileName);
file.SaveAs(phisicalPath);
DriverReg newRecord = new DriverReg();
newRecord.FullName = model.FullName;
newRecord.Address = model.Address;
newRecord.Postcode = model.Postcode;
newRecord.Contact = model.Contact;
newRecord.Email = model.Email;
newRecord.County = model.County;
newRecord.File = phisicalPath;
newRecord.Date = DateTime.Now;
db.DriverRegs.Add(newRecord);
db.SaveChanges();
return RedirectToAction("Index");
}
}
return View(model);
}
CREATE詳細ビュー
<div class="form-group">
@Html.LabelFor(model => model.File, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
<input type="file" class="file-input" name="file" />
@Html.ValidationMessageFor(model => model.File, "", new { @class = "text-danger" })
</div>
</div>
VIEW
<dt>
@Html.DisplayNameFor(model => model.File)
</dt>
<dd>
@Html.Image(@Model.File, "image")
</dd>
おかげスティーブンの内容を保存し、私はあなたのコードを試みたと動作しませんでした、それはエラーを**ファイルは物理パスですが、仮想パスが予想されていました** – prezequias
ありがとう、アシュリーからの更新は完璧でした。あなたは私の日を救いました – prezequias