如何在我的ActionLink中添加rel =“nofollow?

时间:2011-07-22 16:45:05

标签: asp.net-mvc asp.net-mvc-3 razor

我有以下内容:

@Html.ActionLink("Register", "Register", "Users")

我想将链接包含以下内容:

title="Register your ID" 
rel="nofollow"

有没有办法可以用MVC3做到这一点?

2 个答案:

答案 0 :(得分:4)

只需使用ActionLink方法的正确重载:

@Html.ActionLink(
    "Register",                           // linkText
    "Register",                           // actionName
    "Users",                              // controllerName
    null,                                 // routeValues
    new {                                 // htmlAttributes
        title = "Register your ID", 
        rel = "nofollow" 
    }
)

应该生成(假设默认路由设置):

<a href="/Users/Register" rel="nofollow" title="Register your ID">Register</a>

答案 1 :(得分:0)

@Html.ActionLink("Register", "Register", "Users", null,
    new {title = "Register your ID", rel="nofollow")

框架将解析该对象并将项目作为属性放置在渲染锚点中。