Reputation: 71
I want to display images from other sever by using view and controller by asp.net mvc. how can i do? can u tell me detail and give me detail an exmaple? wait to see your answer.
Thanks Nara
Upvotes: 1
Views: 2901
Reputation: 22485
or you could make a little html helper:
public static MvcHtmlString Image(this HtmlHelper helper,
string url,
object htmlAttributes)
{
return Image(helper, url, null, htmlAttributes);
}
public static MvcHtmlString Image(this HtmlHelper helper,
string url,
string altText,
object htmlAttributes)
{
TagBuilder builder = new TagBuilder("image");
var path = url.Split('?');
string pathExtra = "";
if(path.Length >1)
{
pathExtra = "?" + path[1];
}
builder.Attributes.Add("src", VirtualPathUtility.ToAbsolute(path[0]) + pathExtra);
builder.Attributes.Add("alt", altText);
builder.MergeAttributes(new RouteValueDictionary(htmlAttributes));
return MvcHtmlString.Create( builder.ToString(TagRenderMode.SelfClosing));
}
typical usage:
<%=Html.Image("~/content/images/ajax-loader.gif", new{style="margin: 0 auto;"})%>
enjoy..
Upvotes: 1
Reputation: 1038720
To display image in a view you could use the <img>
tag:
<img src="http://someotherserver/path/to/some/image.png" alt="" />
Upvotes: 2