将图像路径更改为外部链接

时间:2014-02-04 11:37:34

标签: c# asp.net-mvc url-routing

我有一个返回带有图像的FileResult的路由。

查看:

<img src="@Url.RouteUrl("HomeProductImage", new { id = Model.ProductId })" />

路由到行动:

routes.MapRouteLowercase("HomeProductImage", "{id}.jpg", new { controller = "Home", 
    action = "ProductImage", id = "" }, new { id = @"\d+" });

public FileResult ProductImage(int id)
{
     // ...
     return File(filename, "image/jpeg");
}

如何在不更改视图的情况下更改路径,从其他域获取图像?

EG。而不是domain.com/product/123.jpg - &gt; otherDoamin.com/product/123.jpg

1 个答案:

答案 0 :(得分:1)

这是不可能的,您应该编写一个帮助方法来返回图像的完整网址。

public static MvcHtmlString ImageUrl(this HtmlHelper html, string imageName)
{
    return String.Format("http://somedomain.com/path/to/image/{0}", imageName);
}
相关问题