Add An Anchor To RedirectToAction's Result?

2019-05-10 11:20发布

问题:

I'm trying to create an extension method similar to MVCContrib's RedirectToAction method by creating a method that will take an #anchor argument and add it to the Url. I am familiar with this question but it's not strongly typed. It's also possible to add values to the query-string, but that won't work for an anchor.

public static RedirectToRouteResult RedirectToAction<T>(this Controller controller, Expression<Action<T>> action, string anchor) where T : Controller
{
   var result = new RedirectToRouteResult<T>(action);

   // how can I add the #anchor to the result's url?

   return result;
}