Advertisement
Guest User

Untitled

a guest
Jul 6th, 2015
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.88 KB | None | 0 0
  1. using System.IO;
  2.  
  3. namespace System.Web.Mvc
  4. {
  5.     public static class ImageHelper
  6.     {
  7.         public static MvcHtmlString ImageTag(string imageUrl, string imageSize, string alt = "", string classes = "")
  8.         {
  9.             var extension = Path.GetExtension(imageUrl);
  10.             var builder = new TagBuilder("img");
  11.             string fullImageUrl = (imageUrl.Substring(0, imageUrl.Length - extension.Length)) + ImageSize.GetSize(imageSize) + extension;
  12.             builder.MergeAttribute("src", fullImageUrl);
  13.  
  14.             if (alt != "")
  15.             {
  16.                 builder.MergeAttribute("alt", alt);
  17.             }
  18.            
  19.             if (classes != "")
  20.             {
  21.                 builder.MergeAttribute("class", classes);
  22.             }
  23.            
  24.  
  25.             return MvcHtmlString.Create(builder.ToString(TagRenderMode.SelfClosing));
  26.         }
  27.     }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement