码迷,mamicode.com
首页 > Web开发 > 详细

自定义Image HtmlHelper

时间:2014-09-10 17:07:20      阅读:171      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   color   os   io   ar   div   cti   

        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

标签:style   blog   http   color   os   io   ar   div   cti   

原文地址:http://www.cnblogs.com/freeliver54/p/3964536.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!