ASP.Net MVC RedirectToAction with anchor

☆樱花仙子☆ 提交于 2019-12-17 08:11:50

问题


I have the following problem: For example I have route like this:

routes.Add(new Route("forums/thread/{threadOid}/last", new MvcRouteHandler())
           Defaults = new RouteValueDictionary(
             new { controller = "Thread", action ="ShowThreadLastPostPage"}),
        Constraints = new RouteValueDictionary(new { threadOid = @"^\d+$" })
    }
);

Is there a way using RedirectToAction method navigate to the URL like this:

forums/thread/{threadOid}/last#postOid


回答1:


I think you should use the Redirect method along with Url.RouteUrl to accomplish it.

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



回答2:


Another alternative with Url.Action:

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


来源:https://stackoverflow.com/questions/602788/asp-net-mvc-redirecttoaction-with-anchor

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!