我有以下问题: 例如,我有这样的路线:
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
答案 0 :(得分:149)
我认为你应该使用Redirect
方法和Url.RouteUrl
来完成它。
return Redirect(Url.RouteUrl(new { controller = "Thread", action = "ShowThreadLastPostPage", threadOid = threadId }) + "#" + postOid);
答案 1 :(得分:17)
Url.Action
的另一种选择:
return Redirect(Url.Action("ShowThreadLastPostPage", "Thread", new { threadOid = threadOid }) + "last#" + postOid);