Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-mvc/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
ASP.Net MVC重定向到带有锚的操作_Asp.net_Asp.net Mvc_Fragment Identifier - Fatal编程技术网

ASP.Net MVC重定向到带有锚的操作

ASP.Net MVC重定向到带有锚的操作,asp.net,asp.net-mvc,fragment-identifier,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

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

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的方法,如下所示:

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

与此答案类似,但这是否会导致对客户端进行渲染,然后向服务器发出新请求,然后再进行另一次渲染?如果是这样的话,还有其他方法可以避免这种情况吗?这个解决方案很难测试,但它很可能是唯一的解决方案。有关ASP.NET MVC核心,请参阅。