开发者

Helper for tag html a

is there any helper in asp.net MVC3

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

?

Not for开发者_JS百科 an action but to a static link


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));
    }
 }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜