ImageActionLink
public static MvcHtmlString ImageActionLink(this HtmlHelper htmlHelper, string imageUrl, string altText, string actionName, object routeValues, object htmlAttributes = null) { TagBuilder imgBuilder = new TagBuilder("img"); imgBuilder.MergeAttribute("src", imageUrl); imgBuilder.MergeAttribute("alt", altText); var urlHelper = new UrlHelper(htmlHelper.ViewContext.RequestContext, htmlHelper.RouteCollection); TagBuilder linkBuilder = new TagBuilder("a"); linkBuilder.MergeAttribute("href", urlHelper.Action(actionName, routeValues)); var text = linkBuilder.ToString(TagRenderMode.StartTag); text += imgBuilder.ToString(TagRenderMode.SelfClosing); text += linkBuilder.ToString(TagRenderMode.EndTag); if (htmlAttributes != null) { var attributes = HtmlHelper.AnonymousObjectToHtmlAttributes(htmlAttributes); linkBuilder.MergeAttributes(attributes); } return MvcHtmlString.Create(text); }
..
'개발 > C# .NET' 카테고리의 다른 글
ASP.NET MVC Grid Table (0) | 2014.07.29 |
---|---|
[MVC] DropDownList에 Enum 바인딩 (0) | 2011.09.21 |
C# machine key 생성하기 (0) | 2011.07.05 |