帮手标记HTML中 [英] Helper for tag html a

查看:142
本文介绍了帮手标记HTML中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有在asp.net MVC3的任何帮助。

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

推荐答案

我不相信有,但我不知道你为什么会想要一个。你实际上更code结束:

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

这篇关于帮手标记HTML中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆