3

is there any helper in asp.net MVC3

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

?

Not for an action but to a static link

ridermansb
  • 10,779
  • 24
  • 115
  • 226

1 Answers1

3

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:

 public static class LinkExtensions
 {
    public static 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));
    }
 }
dahlbyk
  • 75,175
  • 8
  • 100
  • 122
  • There is no method 'Link' in class'html'. I want to make more standard, after all textbox, actions, all have dropbox Usage helpers. So it lacks the (static link) – ridermansb Mar 23 '11 at 11:53
  • I had to declare the first parameter as `this HtmlHelper` but it worked otherwise. – Eric J. Apr 12 '11 at 06:21
  • In that case, you'll have more flexibility if you make the method generic: `Link(this HtmlHelper helper, ...` – dahlbyk Apr 12 '11 at 08:48