programing

ASP.Net MVC 앵커가 있는 작업으로 리디렉션

i4 2023. 7. 10. 21:59
반응형

ASP.Net MVC 앵커가 있는 작업으로 리디렉션

다음과 같은 문제가 있습니다.예를 들어 다음과 같은 경로가 있습니다.

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

반응형