【问题标题】:Url.Action passing fragmentUrl.Action 传递片段
【发布时间】:2012-06-08 23:31:12
【问题描述】:

如何在 ASP.NET MVC 中使用 UrlHelper 传递内联锚点?

例如,如果我有一个 URL:

/Foo/Bar/Information/FAQ#toc

我正在使用以下 Url.Action 来获取除 #toc 片段之外的所有内容

<a class="next" href='@Url.Action("Bar", "Foo", new { subPath = "Information/FAQ" } )'>My Link Text</a>

我的问题: Url.Action 是否有重载传递 #toc 片段?我宁愿不使用一些硬编码的连接或@Url.Content(诚然,我大部分时间都在作弊)。

【问题讨论】:

  • 这里有几个解决方案...stackoverflow.com/questions/274586/…
  • 不是 100% 确定,但似乎 Url.Action 没有过载,但规范的解决方案是改用 Html.ActionLink 嗯?谢谢布赖恩!

标签: asp.net-mvc asp.net-mvc-routing


【解决方案1】:

使用 LinkExtensions 中的 Html.ActionLink 将“toc”传递给片段参数:

https://msdn.microsoft.com/en-us/library/dd460522.aspx

【讨论】:

    【解决方案2】:
    @Url.Action("view", "application", new { id = item.ApplicationId }, null, null, "Optt01")
    

    会带你到/application/view/fc0fc182-d4e4-4b65-9d03-10be74c20212#Optt01

    【讨论】:

      猜你喜欢
      • 2020-09-10
      • 1970-01-01
      • 2015-01-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-02-13
      • 2015-08-01
      相关资源
      最近更新 更多