开发者

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

I want to refer an 开发者_JAVA技巧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?


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" />


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);
    }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜