带锚的 MVC RedirectToAction

我有以下问题: 例如,我有这样的路线:

routes.Add(new Route("forums/thread/{threadOid}/last", new MvcRouteHandler())
Defaults = new RouteValueDictionary(
new { controller = "Thread", action ="ShowThreadLastPostPage"}),
Constraints = new RouteValueDictionary(new { threadOid = @"^\d+$" })
}
);

使用 RedirectToAction 方法是否可以像下面这样导航到 URL:

forums/thread/{threadOid}/last#postOid

23419 次浏览

I think you should use the Redirect method along with Url.RouteUrl to accomplish it.

return Redirect(Url.RouteUrl(new { controller = "Thread", action = "ShowThreadLastPostPage", threadOid = threadId }) + "#" + postOid);

Another alternative with Url.Action:

return Redirect(Url.Action("ShowThreadLastPostPage", "Thread", new { threadOid = threadOid }) + "last#" + postOid);