12

Possible Duplicate:
Including an anchor tag in an asp.net mvc Html.ActionLink

The code : @Html.ActionLink("Link", "Action", "Controller", new { id = Id } )

For the moment I can generate links like this :

http://mywebsite/Controller/Action/Id

I would like to generate a link like this :

http://mywebsite/Controller/Action/Id#divId

But I can't edit the route/create another route.

What is the best solution?

Community
  • 1
  • 1
Giu
  • 1,832
  • 2
  • 16
  • 31
  • 1
    There is similar post....http://stackoverflow.com/questions/2920983/create-a-t4mvc-actionlink-with-url-fragment – Sagar Modi Dec 12 '12 at 08:30

1 Answers1

17

Just use the proper overload of the ActionLink helper:

@Html.ActionLink(
    linkText: "Link",
    actionName: "Action",
    controllerName: "Controller",
    protocol: null,
    hostName: null,
    fragment: "divId",
    routeValues: new { id = Id },
    htmlAttributes: null
)

will generate:

<a href="/Controller/Action/123#divId">Link</a>
Darin Dimitrov
  • 1,023,142
  • 271
  • 3,287
  • 2,928