Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.IO;
- namespace System.Web.Mvc
- {
- public static class ImageHelper
- {
- public static MvcHtmlString ImageTag(string imageUrl, string imageSize, string alt = "", string classes = "")
- {
- var extension = Path.GetExtension(imageUrl);
- var builder = new TagBuilder("img");
- string fullImageUrl = (imageUrl.Substring(0, imageUrl.Length - extension.Length)) + ImageSize.GetSize(imageSize) + extension;
- builder.MergeAttribute("src", fullImageUrl);
- if (alt != "")
- {
- builder.MergeAttribute("alt", alt);
- }
- if (classes != "")
- {
- builder.MergeAttribute("class", classes);
- }
- return MvcHtmlString.Create(builder.ToString(TagRenderMode.SelfClosing));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement