Rica
Rica

Reputation: 88

Display File From Local Drive in MVC view

I have been trying to display local Pdffile from D drive in a view of MVC along with other data.I have tried out Iframe and even added extensions for browsers like local links to display but of no use.I have been stuck with this problem since 3 days.I have tried out the following code.

<iframe src="@Url.Content("file:///D:/PdfsFolder/" + Model.FileName)"></iframe>

This works fine for me in IE but not working in Other browsers.When I try to open only the file using hyperlink it works in all browsers.My problem is to display it along with other data.please help me out If there is any other way to display that file in the View other than Iframe.

Upvotes: 0

Views: 3849

Answers (2)

stylishCoder
stylishCoder

Reputation: 385

you have to write a controller & action that will fetch the file and pass back to the response:

public ActionResult TestPdf()
{
    return File(@"d:\test.pdf", "application/pdf");
}

and now in your view you could use an iframe to point it to this controller action:

<iframe src="<%= Url.Action("TestPdf", "SomeController") %>"></iframe>

Upvotes: 2

stylishCoder
stylishCoder

Reputation: 385

why are to trying to attach a file from drive use root directory of project to pic the files like create a folder in your project put files their and try below code

<img src="<%= Url.Content("~/Content/UserImages/FileName.jpg") %>" />

Upvotes: 0

Related Questions