1

我正在尝试从数据库中动态加载图像,因为我使用的是:

<img src='@Url.Action("GetImage/${ID}", "Home")' alt = "${name} image" />

但它不会反映到控制器,但如果我静态地放:

<img src='@Url.Action("GetImage/1", "Home")' alt = "${name} image" />

然后它反映到控制器并显示图像。我想将 ID 从视图动态发送到控制器。如何将动态值与“GetImage”连接起来

我的控制器代码是:

public ActionResult GetImage(int id)
{
  var imgquery = (from img in dbContext.Listdetails where img.ID == id
  select new
  {
    Image = img.Image
  }).FirstOrDefault();
  {
    System.IO.MemoryStream outStream = new System.IO.MemoryStream();
    byte[] Image = imgquery.Image;
    return File(Image, "Image/jpg");
  }
}

有什么建议么?

4

0 回答 0