ASP.net MVC 3 将任意文本添加到 ActionLink 的末尾
您好,我有一个关于 Html.ActionLink 的问题。
想象一下:
@Html.ActionLink(item.title, "Singlet", new { id = item.blog_id })
生成 http://[url]/[controller]/Singlet/[id]
但如果我想在末尾添加一些更任意的数据后缀怎么办?例如:
http://[url]/[controller]/Singlet/[id]/#comments
跳转到评论div。我知道我可以自己制作字符串,例如:
@( new HtmlString(String.Format("<a href=\"Blog/Singlet/{0}/#comments\">link to comments</a>", item.blog_id)) )
但我希望有一种更干净的方法,也许使用 ActionLink?
谢谢
Hi I have a question about Html.ActionLink.
Imagine:
@Html.ActionLink(item.title, "Singlet", new { id = item.blog_id })
produces http://[url]/[controller]/Singlet/[id]
But what if I want to suffix some more arbitrary data at the end? For example:
http://[url]/[controller]/Singlet/[id]/#comments
To jump to the comments div. I know I can just make the string myself with something like:
@( new HtmlString(String.Format("<a href=\"Blog/Singlet/{0}/#comments\">link to comments</a>", item.blog_id)) )
But I am hoping there is a cleaner way, perhaps with ActionLink?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
也许这样的事情可能会起作用:
Maybe something like this might work:
你可以这样做:
You can do this instead:
看看这个答案,看看它是否有帮助:
创建 T4MVC ActionLink with urlfragment
看起来这个功能是在 ASP.NET MVC 2 中添加的,所以它应该在 3 中也可用。以下是
ActionLink
方法的文档:http:// /msdn.microsoft.com/en-us/library/dd460522.aspx
具体来说,
fragment
参数似乎是您感兴趣的参数。Have a look at this answer and see if it helps:
Create a T4MVC ActionLink with url fragment
It looks like the feature was added in ASP.NET MVC 2, so it should be available in 3 as well. Here's the documentation for the
ActionLink
method:http://msdn.microsoft.com/en-us/library/dd460522.aspx
Specifically, it looks like the
fragment
parameter is the one you're interested in.