Saeid
Saeid

Reputation: 13582

Display the file in page when the type of that is not specified

When I want to show an image I use something like this:

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

And in View:

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

So assume we have some other types of file like txt, pdf, ... And I think to use a general tag to show all kind of files instead of <img>. Does any one have any idea about it?

Upvotes: 1

Views: 59

Answers (1)

LukLed
LukLed

Reputation: 31842

It is not easy, because some files need initialization or need additional declarations to specify how they should be presented, but you can try with iframe:

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

It will use browser built-in way of presenting documents.

Upvotes: 1

Related Questions