There is an overload of the ActionLink helper that allows you to specify the fragment:
@Html.ActionLink(
"Link Text", // linkText
"Action", // actionName
"Controller", // controllerName
null, // protocol
null, // hostName
"fragment", // fragment
new { id = "123" }, // routeValues
null // htmlAttributes
)
will produce (assuming default routes):
<a href="/Controller/Action/123#fragment">Link Text</a>
UPDATE:
and if you wanted to do this within a controller action performing a redirect you could 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);
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…