Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static class HtmlHelperExtensions
- {
- public static string Image( this HtmlHelper helper,
- string url,
- string altText,
- object htmlAttributes )
- {
- TagBuilder builder = new TagBuilder( "img" );
- builder.Attributes.Add( "src", url );
- builder.Attributes.Add( "alt", altText );
- builder.MergeAttributes( new RouteValueDictionary( htmlAttributes ) );
- return builder.ToString( TagRenderMode.SelfClosing );
- }
- }
- <%= Html.Image( Url.Content( "~/Content/images/img.png" ),
- "alt text",
- new { id = "myImage", border = "0" } )
- %>
- <img src="<%= Url.Content( "~/content/..." ) %>"
- alt="alt text"
- class="has-border" />
- <img src="" alt="" />
- <img src="<%= ViewData["ImageSource"] %>" alt="" />
- <img src="<%= ViewData.Model.ImageSource %>" alt="" />
- <img src="<%= ResolveUrl(ViewData.Model.ImageSource) %>" alt="" />
- public static MvcHtmlString Image(this HtmlHelper helper, string url, string altText, object htmlAttributes)
- {
- TagBuilder builder = new TagBuilder("img");
- builder.Attributes.Add("src", url);
- builder.Attributes.Add("alt", altText);
- builder.MergeAttributes(new RouteValueDictionary(htmlAttributes));
- return MvcHtmlString.Create(builder.ToString(TagRenderMode.Normal));
- }
- @Html.Image( Url.Content( "~/Content/images/img.png" ),
- "alt text",
- new { id = "myImage", border = "0" } )
- <img src="/Content/image/mypic.png" alt="a picture available anywhere" />
Add Comment
Please, Sign In to add comment