UrlHelper.Action: would like to create a link that ends with '#something'

I am trying to create a link with Url.Action that ends with #something ; I suppose there is something in the route values ​​to do it right, but I could not find it with Google.

So far I have tried Url.Action("action", "controller", new {id="something", Area="area"}) . The resulting link is the expected / action / controller / area, but in the end I cannot commit #something.

Url-wise, I could probably get away from the word <a href="<%= Url.Action(..) %>#something"> , but that doesn't seem to me particularly pleasant; I am looking for the best solution.

+4
source share
2 answers

There is no overload of the Url.Action() method that does this for you. Ether you will have to do it the way you suggest (just adding it after calling Url.Action() ) or create your own extension method.

Your extension method might look something like this:

 public static MvcHtmlString Action(this UrlHelper urlHelper, string action, string controller, string hash) { return string.Format("{0}#{1}", urlHelper.Action(action, controller), hash); } 
+12
source

You must use one of the LinkExtensions.ActionLink methods. The documentation can be found here: http://msdn.microsoft.com/en-us/library/system.web.mvc.html.linkextensions.actionlink.aspx

0
source

All Articles