如何在ActionLink中添加书签/片段? [英] How can I include a bookmark/fragment in an ActionLink?

查看:99
本文介绍了如何在ActionLink中添加书签/片段?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:
在asp.net mvc中包含锚标记Html.ActionLink

Possible Duplicate:
Including an anchor tag in an asp.net mvc Html.ActionLink

代码:@Html.ActionLink("Link", "Action", "Controller", new { id = Id } )

目前,我可以生成这样的链接:

For the moment I can generate links like this :

http://mywebsite/Controller/Action/Id

我想生成一个这样的链接:

I would like to generate a link like this :

http://mywebsite/Controller/Action/Id#divId

但是我无法编辑路线/创建其他路线.

But I can't edit the route/create another route.

什么是最佳解决方案?

推荐答案

只需使用 proper overload (位于ActionLink帮助器中):

Just use the proper overload of the ActionLink helper:

@Html.ActionLink(
    linkText: "Link",
    actionName: "Action",
    controllerName: "Controller",
    protocol: null,
    hostName: null,
    fragment: "divId",
    routeValues: new { id = Id },
    htmlAttributes: null
)

将生成:

<a href="/Controller/Action/123#divId">Link</a>

这篇关于如何在ActionLink中添加书签/片段?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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