ASP.Net MVC RedirectToAction アンカー付き 質問する

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

ベストアンサー1

Redirectそれを達成するには、このメソッドを一緒に使用する必要があると思いますUrl.RouteUrl

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

おすすめ記事