Last active
May 28, 2018 20:30
Revisions
-
cigano revised this gist
Sep 15, 2014 . 1 changed file with 2 additions and 0 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,3 +1,5 @@ <!-- language: c# --> public static class HtmlExtensions { public static IHtmlString FontAwesomeActionLink(this HtmlHelper htmlHelper, string linkText, -
cigano revised this gist
Sep 15, 2014 . 1 changed file with 8 additions and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,7 +1,14 @@ public static class HtmlExtensions { public static IHtmlString FontAwesomeActionLink(this HtmlHelper htmlHelper, string linkText, string actionName, string fontAwesomeClass, object routeValues = null, object htmlAttributes = null) { return FontAwesomeActionLink(htmlHelper, linkText, actionName, null, fontAwesomeClass, routeValues, htmlAttributes); } public static IHtmlString FontAwesomeActionLink(this HtmlHelper htmlHelper, string linkText, string actionName, string controllerName, string fontAwesomeClass, object routeValues = null, object htmlAttributes = null) { var targetUrl = UrlHelper.GenerateUrl(null, actionName, controllerName, ObjectToDictionary(routeValues), htmlHelper.RouteCollection, htmlHelper.ViewContext.RequestContext, true); return new MvcHtmlString(GenerateLink(linkText, targetUrl, fontAwesomeClass, HtmlHelper.AnonymousObjectToHtmlAttributes(htmlAttributes))); -
cigano created this gist
Sep 15, 2014 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,45 @@ public static class HtmlExtensions { public static IHtmlString FontAwesomeActionLink(this HtmlHelper htmlHelper, string linkText, string actionName, string controllerName, string fontAwesomeClass, object routeValues, object htmlAttributes) { var targetUrl = UrlHelper.GenerateUrl(null, actionName, controllerName, ObjectToDictionary(routeValues), htmlHelper.RouteCollection, htmlHelper.ViewContext.RequestContext, true); return new MvcHtmlString(GenerateLink(linkText, targetUrl, fontAwesomeClass, HtmlHelper.AnonymousObjectToHtmlAttributes(htmlAttributes))); } private static string GenerateLink(string linkText, string targetUrl, string fontAwesomeClass, IDictionary<string, object> htmlAttributes ) { var a = new TagBuilder("a"); a.MergeAttributes(htmlAttributes); a.MergeAttribute("href", targetUrl); var i = new TagBuilder("i"); i.MergeAttribute("class", "fa " + fontAwesomeClass); a.InnerHtml = i.ToString(TagRenderMode.Normal) + " " + linkText; return a.ToString(TagRenderMode.Normal); } public static RouteValueDictionary ObjectToDictionary(object value) { var dictionary = new RouteValueDictionary(); if (value != null) { foreach (PropertyInfo property in value.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance) .Where(prop => prop.GetIndexParameters().Length == 0 && prop.GetMethod != null)) { dictionary.Add(property.Name, property.GetValue(value)); } } return dictionary; } }