1

当我想显示图像时,我使用这样的东西:

public ActionResult Show(int id) {
  var MyFile = GetFromDB(id);
  return File(MyFile.Data, MyFile.ContentType);
}

在视图中:

<img alt ="" src='@Url.Action("show", new { id = 36 })'/>

所以假设我们有一些其他类型的文件,比如txt, pdf, ... 而且我认为使用通用标签来显示所有类型的文件而不是<img>. 有人对此有任何想法吗?

4

1 回答 1

1

这并不容易,因为有些文件需要初始化或需要额外的声明来指定它们应该如何呈现,但你可以尝试使用 iframe:

<iframe src='@Url.Action("show", new { id = 36 })'></iframe>

它将使用浏览器内置的方式呈现文档。

于 2012-06-16T12:20:20.410 回答