Mangesh Kaslikar
Mangesh Kaslikar

Reputation: 591

Display file (PDF/TXT) on form brought from Database in MVC ASP.NET

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.

Upvotes: 0

Views: 925

Answers (2)

yasth
yasth

Reputation: 171

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.

Upvotes: 0

Max
Max

Reputation: 9899

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.

Upvotes: 0

Related Questions