Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I include a bookmark/fragment in an ActionLink? [duplicate]

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?

like image 468
Giu Avatar asked Dec 12 '12 08:12

Giu


1 Answers

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>
like image 52
Darin Dimitrov Avatar answered Sep 19 '22 21:09

Darin Dimitrov