开发者

ASP.NET MVC using Url.Content with dynamic images

How can I create a dynamic url to display an image?

I am creating a web page that lists search results of products and their associated images.

I tried using Url.Content, but it does not format the url correctly.

Code I created:

<img src="../../Images/<%: product.PicFileName %>" alt="photo" />

Html that was output:

<img src=".. ..="" Images="" nopic.开发者_运维百科jpg="" alt="photo" ="">

I also tried creating a helper method but it created the exact same output:

public static string GetPicUrl(string picFileName)
    {
        string picUrl = "../../" + picFileName;

        return picUrl;
    }


Just tried this:

<img src="<%: Url.Content("/Images/" + filename) %>" alt="foo" />

where filename = "foo.jpg" and it gives me <img src="/Images/foo.jpg" alt="foo"/> which links to http://hostname/Images/foo.jpg

Please let us know what format you want the Url in if this isn't what you had in mind and I will try to help you some more.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜