【发布时间】:2019-04-05 17:13:39
【问题描述】:
我只需要显示我插入的多个图像,它会保存在路径中,但是当他显示时它会显示出来。我不知道我的问题出在哪里,但这是我的代码,请大家帮帮我?
我的控制器
public async Task<ActionResult> Create(Inbox model, IEnumerable<HttpPostedFileBase> files)
{
var currentUser = await manager.FindByIdAsync(User.Identity.GetUserId());
if (ModelState.IsValid)
{
model.User = currentUser;
foreach (var file in files)
{
if (file != null && file.ContentLength > 0)
{
var fileName = Path.GetFileName(file.FileName);
var path = Path.Combine(Server.MapPath("~/FilesAPP"), fileName);
file.SaveAs(path);
path = Url.Content(Path.Combine("~/FilesAPP", fileName));
}
}
db.Inboxs.Add(model);
db.SaveChanges();
string url = Url.Action("List");
return Json(new { success = true, url = url });
}
return View(model);
}
我的模型
public string Files { get; set; }
我的观点
<img width="200" height="150" src="@Url.Content(Model.Files))" />
伙计们,我怎样才能显示我的图片?
【问题讨论】:
-
首先,检查您的浏览器本地主机路径“localhost:0000/FilesAPP/abc.jpg”检查您在浏览器中键入时显示的图像。如果是,则检查您使用时生成的路径,src="@Url.Content(Model.Files))"
标签: c# asp.net-mvc asp.net-mvc-4 razor asp.net-mvc-5