首页 > 代码库 > 自定义Image HtmlHelper

自定义Image HtmlHelper

        public static void Image(this HtmlHelper helper, string src, string alt = null, object htmlAttributes = null)        {            System.Web.UI.HtmlTextWriter writer = new HtmlTextWriter(helper.ViewContext.HttpContext.Response.Output);            System.Web.Mvc.TagBuilder tbImage = new TagBuilder("img");            tbImage.MergeAttribute("src", src);            tbImage.MergeAttribute("alt", alt);            if (htmlAttributes != null)            {                tbImage.MergeAttributes<string, object>(new RouteValueDictionary(htmlAttributes));            }            writer.InnerWriter.Write(tbImage.ToString(TagRenderMode.SelfClosing));        }

 

自定义Image HtmlHelper