Created
January 1, 2013 01:04
-
-
Save SyntaxC4/4424427 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| namespace Net.SyntaxC4.Blog.Examples | |
| { | |
| using System; | |
| using System.Linq.Expressions; | |
| using System.Web.Mvc; | |
| using System.Web.Mvc.Html; | |
| using System.Web.Routing; | |
| public static class HtmlExtensions | |
| { | |
| public static MvcHtmlString ActionLinkWithSpan(this HtmlHelper html, | |
| string linkText, | |
| string actionName, | |
| string controllerName, | |
| object htmlAttributes) | |
| { | |
| RouteValueDictionary attributes = new RouteValueDictionary(htmlAttributes); | |
| TagBuilder linkTag = new TagBuilder("a"); | |
| TagBuilder spanTag = new TagBuilder("span"); | |
| spanTag.SetInnerText(linkText); | |
| // Merge Attributes on the Tag you wish the htmlAttributes to be rendered on. | |
| //linkTag.MergeAttributes(attributes); | |
| spanTag.MergeAttributes(attributes); | |
| UrlHelper url = new UrlHelper(html.ViewContext.RequestContext); | |
| linkTag.Attributes.Add("href", url.Action(actionName, controllerName)); | |
| linkTag.InnerHtml = spanTag.ToString(TagRenderMode.Normal); | |
| return MvcHtmlString.Create(linkTag.ToString(TagRenderMode.Normal)); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment