maztt
maztt

Reputation: 12294

Referring an image that is located on my C drive in asp.net MVC

I want to refer an image located in c:/image/ff.gif/. How can I do that? I tried to do it with img src, but couldn't make it to work. Any ideas?

Upvotes: 0

Views: 823

Answers (2)

Niraj
Niraj

Reputation: 119

Check this here How I am using in MVC.

In View:

    <img src="@Url.Action("FileDownload",new { name=i.fileName})" alt="@i.fileName"/>

In Controller:

    public FileResult FileDownload(string name)
    {
        string FilePath= _ConfigPath+ "\\" + name;
        return File(FilePath, "application/force-download", name);
    }

Upvotes: 1

Darin Dimitrov
Darin Dimitrov

Reputation: 1039398

The image needs to be part of the site if you want to use it directly. If it is situated outside of your site root you could write an action that will fetch the image and serve it:

public ActionResult MyImage()
{
    return File(@"c:\imagefolder\imagell.gif", "image/gif");
}

And then use this action:

<img src="<%= Url.Action("myimage") %>" alt="image description" />

Upvotes: 2

Related Questions