Skip to content

Instantly share code, notes, and snippets.

@davidalpert
Created May 11, 2011 05:27
Show Gist options
  • Save davidalpert/965971 to your computer and use it in GitHub Desktop.
Save davidalpert/965971 to your computer and use it in GitHub Desktop.
HyperLink helpers that depend on FubuMVC's HtmlTags spinoff library
public static class HyperLinkTagHelpers
{
public static HtmlTag HyperLink( this HtmlHelper htmlHelper, string linkText, IUrl url )
{
return htmlHelper.HyperLink( linkText, url, null );
}
public static HtmlTag HyperLink( this HtmlHelper htmlHelper, string linkText, IUrl url, object htmlAttributes )
{
return htmlHelper.HyperLink( linkText, url.ToString(), new RouteValueDictionary( htmlAttributes ) );
}
public static HtmlTag HyperLink( this HtmlHelper htmlHelper, string linkText, string url )
{
return htmlHelper.HyperLink( linkText, url, new RouteValueDictionary() );
}
public static HtmlTag HyperLink( this HtmlHelper htmlHelper, string linkText, string url, object htmlAttributes )
{
return htmlHelper.HyperLink( linkText, url, new RouteValueDictionary( htmlAttributes ) );
}
public static HtmlTag HyperLink( this HtmlHelper htmlHelper, string linkText, string url, IDictionary<string, object> htmlAttributes )
{
var tag = new HtmlTag( "a" ).Text( linkText ).Attr( "href", url );
htmlAttributes.ToList().ForEach( attr => tag.Attr( attr.Key, attr.Value ) );
return tag;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment