As Brad Wilson wrote, you can build your own link in your views by simply concatenating strings. But to append a fragment name to a redirect generated via RedirectToAction (or similar) you'll need something like this:
public class RedirectToRouteResultEx : RedirectToRouteResult {
public RedirectToRouteResultEx(RouteValueDictionary values)
: base(values) {
}
public RedirectToRouteResultEx(string routeName, RouteValueDictionary values)
: base(routeName, values) {
}
public override void ExecuteResult(ControllerContext context) {
var destination = new StringBuilder();
var helper = new UrlHelper(context.RequestContext);
destination.Append(helper.RouteUrl(RouteName, RouteValues));
//Add href fragment if set
if (!string.IsNullOrEmpty(Fragment)) {
destination.AppendFormat("#{0}", Fragment);
}
context.HttpContext.Response.Redirect(destination.ToString(), false);
}
public string Fragment { get; set; }
}
public static class RedirectToRouteResultExtensions {
public static RedirectToRouteResultEx AddFragment(this RedirectToRouteResult result, string fragment) {
return new RedirectToRouteResultEx(result.RouteName, result.RouteValues) {
Fragment = fragment
};
}
}
And then, in your controller, you'd call:
return RedirectToAction("MyAction", "MyController")
.AddFragment("fragment-name");
That should generate the URL correctly.