There is an overload of the ActionLink helper , which allows you to specify a fragment:
@Html.ActionLink( "Link Text", // linkText "Action", // actionName "Controller", // controllerName null, // protocol null, // hostName "fragment", // fragment new { id = "123" }, // routeValues null // htmlAttributes )
will generate (when using default routes):
<a href="/Controller/Action/123#fragment">Link Text</a>
UPDATE:
and if you want to do this as part of the action of the controller performing the redirection, you can use the GenerateUrl method:
public ActionResult Index() { var url = UrlHelper.GenerateUrl( null, "Action", "Controller", null, null, "fragment", new RouteValueDictionary(new { id = "123" }), Url.RouteCollection, Url.RequestContext, false ); return Redirect(url); }
Darin Dimitrov Oct 26 2018-11-11T00: 00Z
source share