development

앵커가있는 ASP.Net MVC RedirectToAction

big-blog 2020. 10. 7. 07:51
반응형

앵커가있는 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:

return Redirect(Url.Action("ShowThreadLastPostPage", "Thread", new { threadOid = threadOid }) + "last#" + postOid);

참고 URL : https://stackoverflow.com/questions/602788/asp-net-mvc-redirecttoaction-with-anchor

반응형