Skip to content Skip to sidebar Skip to footer

Helper For Tag Html A

is there any helper in asp.net MVC3 Go to Google ? Not for an action but to a static link

Solution 1:

I don't believe there is, but I'm not sure why you would want one. You'd actually end up with more code:

<a href="http://www.google.com/">Go to Google</a>

<%: Html.Link("http://www.google.com/", "Go to Google") %>

@Html.Link("http://www.google.com/", "Go to Google")

Update: If you want to create a Link() helper like that above, you would use an extension method:

publicstaticclassLinkExtensions
 {
    publicstatic MvcHtmlString Link(this HtmlHelper helper, string href, string text)
    {
        var builder = new TagBuilder("a");
        builder.MergeAttribute("href", href);
        builder.SetInnerText(text);

        return MvcHtmlString.Create(builder.ToString(TagRenderMode.Normal));
    }
 }

Post a Comment for "Helper For Tag Html A"