1

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

0

2 Answers 2

2

To display image in a view you could use the <img> tag:

<img src="http://someotherserver/path/to/some/image.png" alt="" />
Sign up to request clarification or add additional context in comments.

Comments

1

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..

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.