开发者

How can I add rel="nofollow to my ActionLink?

I have the following:

@Html.ActionLink("Register",开发者_如何学运维 "Register", "Users")

I would like to make the link include the following:

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

Is there a way that I can do this with MVC3?


Simply use the proper overload of the ActionLink method:

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

Should generate (assuming default routes setup):

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


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

The framework will parse that object and place the items as attributes in the rendered anchor.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜