ASP.Net 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
我认为你应该使用Redirect
方法与Url.RouteUrl
来完成它。
return Redirect(Url.RouteUrl(new { controller = "Thread", action = "ShowThreadLastPostPage", threadOid = threadId }) + "#" + postOid);
Url.Action
另一种select:
return Redirect(Url.Action("ShowThreadLastPostPage", "Thread", new { threadOid = threadOid }) + "last#" + postOid);