带锚的ASP.Net MVC RedirectToAction

时间:2009-03-02 15:39:45

标签: asp.net asp.net-mvc fragment-identifier

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

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

2 个答案:

答案 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);