0

I want to display file on my form using MVC.

I am bringing a Byte[] array data from the Database, and using FileContentResult I am converting it into a file.I want to now display this file on my page for viewing . How can it be acheived. What code to write in my View for the same.

tereško
  • 58,060
  • 25
  • 98
  • 150
Mangesh Kaslikar
  • 591
  • 3
  • 13
  • 23

2 Answers2

0

Assuming you're using Razor, rendering a text file can be done as simple as:

<div>
    @(new System.IO.StreamReader("myFile.txt")).ReadToEnd()
</div>

For PDF files, you'll have to find a third-party component to convert to HTML.

Max
  • 9,220
  • 10
  • 51
  • 83
0

You probably don't want to use FileContentResult, that is something generally used for providing the raw file.

In theory though there is nothing different in using any other url

<img src="@Html.ActionLink("View","Image",{id = Model.key})" />

Or you can provide that link in a pdf reference, or as a stylesheet etc.

yasth
  • 171
  • 5