我将图像上传到具有 byte[] 格式的表中。我的问题是,当我在视图上检索它时,图像不会显示。
模型
{
public byte[] image {get; set;}
}
控制器
public async Task<IActionResult> Create(Profile profile, IFormFile image)
{
if (ModelState.IsValid)
{
using (var memoryStream = new MemoryStream())
{
image.CopyTo(memoryStream);
profile.image = memoryStream.ToArray();
}
_context.Add(image);
await _context.SaveChangesAsync();
return RedirectToAction(nameof(Index));
}
return View(image);
}
看法
<img src="@item.image" />