2

How does one pass an inline anchor using the UrlHelper in ASP.NET MVC?

For example, if I have a URL:

/Foo/Bar/Information/FAQ#toc

And I was using the following Url.Action to get everything except the #toc fragment

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

My question: is there an overload for Url.Action to pass in the #toc fragment? I'd rather not use some hardcoded concatenation or @Url.Content (admittedly the way I cheat most of the time).

Filburt
  • 17,626
  • 12
  • 64
  • 115
t3rse
  • 10,024
  • 11
  • 57
  • 84
  • 2
    There are a couple solutions here... http://stackoverflow.com/questions/274586/including-an-anchor-tag-in-an-asp-net-mvc-html-actionlink – Brian Behm Jun 04 '12 at 22:47
  • Not 100% certain but it seems like Url.Action does not have an overload but the canonical solution is to instead use Html.ActionLink eh? Thanks Brian! – t3rse Jun 05 '12 at 14:14

2 Answers2

0

Use Html.ActionLink from LinkExtensions passing the "toc" to the fragment parameter:

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

AntonK
  • 2,303
  • 1
  • 20
  • 26
0
@Url.Action("view", "application", new { id = item.ApplicationId }, null, null, "Optt01")

Will take you to /application/view/fc0fc182-d4e4-4b65-9d03-10be74c20212#Optt01

Jussi Palo
  • 848
  • 9
  • 26