85

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

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

4

2 回答 2

157

我认为您应该使用该Redirect方法Url.RouteUrl来完成它。

return Redirect(Url.RouteUrl(new { controller = "Thread", action = "ShowThreadLastPostPage", threadOid = threadId }) + "#" + postOid);
于 2009-03-02T15:44:39.750 回答
22

另一种选择Url.Action

return Redirect(Url.Action("ShowThreadLastPostPage", "Thread", new { threadOid = threadOid }) + "last#" + postOid);
于 2016-02-04T00:49:21.433 回答