UrlHelper.Action:想要生成一个以“#something”结尾的链接;
我正在尝试创建一个带有 Url.Action 的链接,该链接以 #something 结尾;我认为路由值中有一些东西可以正确地执行此操作,但我无法通过 Google 找到它。
到目前为止,我尝试了 Url.Action("action", "controller", new {id="something", Area="area"})
。生成的链接是预期的 /action/controller/area,但我最终无法解决 #something。
就网址而言,我可能可以说 但这并不让我觉得特别好;我正在寻找更好的解决方案。
I'm trying to create a link with Url.Action, which ends with a #something; I presume there's something in the route values to do this properly, but I couldn't find it with Google.
So far, I tried Url.Action("action", "controller", new {id="something", Area="area"})
. The resulting link is the expected /action/controller/area, but I can't tack the #something in the end.
Url-wise, I could probably get away with saying <a href="<%= Url.Action(..)
but that doesn't strike me as particularly nice; I'm looking for a better solution.
%>#something">
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您应该使用 LinkExtensions.ActionLink 方法之一。文档可以在这里找到:
http://msdn.microsoft.com /en-us/library/system.web.mvc.html.linkextensions.actionlink.aspx
You should use one of the LinkExtensions.ActionLink methods. Documentation can be found here:
http://msdn.microsoft.com/en-us/library/system.web.mvc.html.linkextensions.actionlink.aspx
Url.Action()
方法没有重载来为您执行此操作。另外,您必须按照您建议的方式执行此操作(只需在调用Url.Action()
之后添加它)或创建您自己的扩展方法。您的扩展方法可能如下所示:
There is no overload of the
Url.Action()
method that does this for you. Ether you will have to do it in the way you suggest (by simply adding it after the call toUrl.Action()
) or create your own extension method.Your extension method can look something like this: