Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Helper for tag html a

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

like image 636
ridermansb Avatar asked Nov 28 '25 15:11

ridermansb


1 Answers

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));
    }
 }
like image 186
dahlbyk Avatar answered Dec 01 '25 07:12

dahlbyk



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!