views:

135

answers:

1

I'm trying to use Html.RouteLink within a view to generate a link to a named anchor on another page. There's a few definitions for RouteLink that include a fragment option but I'm trying to figure out if there's another way.

public static string RouteLink(
    this HtmlHelper htmlHelper,
    string linkText,
    string routeName,
    string protocol,
    string hostName,
    string fragment,
    Object routeValues,
    Object htmlAttributes
)

is the obvious solution, but kind of clunky seeming. I'd prefer to be able to do something like

Html.RouteLink("Looga", new { Controller = "Cooga", Action = "Aooga", Fragment = "Fooga" })

and have that return

<a href="/Cooga/Aooga#Fooga">Looga</a>

Is that possible or will I need to specify every little part of the URL to get fragment using the built-in helpers. I could also just do it manually like

<a href="<%= Url.RouteUrl(new { Controller = "Cooga", Action = "Aooga" }) %>#Fooga>Looga</a>

but it seems like something RouteLink should be able to handle more elegantly.

+1  A: 
Russell Giddings
That's probably what I'll end up doing. Sorry about the janky example, I wasn't paying enough attention. Fixed now.
Tivac